Comments (7)
Hi @TristanPct,
If you had the data-router-disabled
attribute to your link Highway won't attach any click
listener to it meaning you can do the event.preventDefault()
like you would do usually because the link is not attache to Highway.
Can you please try and come back to us ?
Thanks,
Anthodpnt
from highway.
Yes, it's what I do for the moment.
My use case is:
- By default use Highway router on links
- If users windows width is small prevent links click
So I tried something like:
function onLinkClick(event) {
if (window.innerWidth < 1150) { // Small screen no redirect
event.preventDefault(); // Ignored by Highway
//...
} else { // Normal case
//...
}
}
For the moment I have to add data-router-disabled
on my links and:
function onLinkClick(event) {
if (window.innerWidth < 1150) { // Small screen no redirect
event.preventDefault(); // Prevent browser redirection
//...
} else { // Normal case
highwayCore.redirect(event.target.attributes["href"].value);
//...
}
}
from highway.
If I understand you want to disable the transition on small screens ?
Why don't you just call Highway.Core
when the screen is over 1150 ?
Why would you remove the click on a link on mobile but not on desktop ?
from highway.
I want to disable my links (not only the transition) on mobile for a menu like this:
- Parent 1
- Child 1.1 (Parent 1 alias)
- Child 1.2
- Parent 2
- Child 2.1 (Parent 2 alias)
- Child 2.1
On desktop all links are visible, on mobile I have a burger menu, Child 2.1 is visible only if I click on Parent 2, but if I'm redirected to Parent 2's page I can't see the Child.
So on mobile I have to prevent default redirection behavior on click, just for parents links.
With my second script, it works like I want.
It's more a suggestion than a bug to add something allowing to programmatically disable the router on a link click.
from highway.
My suggestion would be to create both a a
and a button
in your DOM and play with CSS to display one or the other based on the window size instead of hacking the Javascript to disable the event on mobile because you have a burger menu.
But the question to disable the router on selected links has been asked and we'll take a look to add this feature as soon as possible.
Best regards,
Anthodpnt
from highway.
I'm using two menus (one for mobile) and (on for desktop) and it's working perfect to display data-router-disabled
on Parent's to make a nice dropdown :)
from highway.
I suppose this issue can be closed for now :)
from highway.
Related Issues (20)
- Javascript functions doesn't works on the second time HOT 1
- Locomotive scroll not updating after page transition HOT 3
- I can't get the HIGHWAY.redirect() to work HOT 1
- Updating CSS for incoming page – (Highway maintains the outgoing page's CSS) HOT 5
- data-transition attribute no longer works in 2.2.2 HOT 2
- Update /refresh/bind links dynamically created with javascript HOT 1
- New href with highway HOT 13
- Adding additional headers to page requests
- Add index.d.ts file for better IDE typehinting
- back/forward buttons pressed during transition break the website
- Facebook Pixel Tracking HOT 3
- Fatal error on transition to mismatching URL scheme, while remaining on the same domain
- Can't work with CDN
- Improper use of DOM events
- Highway not working with DOM elements rendered by javascript HOT 1
- H.redirect always refresh page HOT 1
- Help
- H is undefined HOT 1
- Navigation with parameters and anchor not working
- Javascript not working after page transition HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from highway.