Comments (12)
So you just want the hash part of an URL to be kept through route transitions? What about it changing and hashchange events?
from router5.
I figure that'd be ignored by Router5 so that the browser can scroll to those elements or other JS events can process (like if the hash is being used to monitor which tab is open from jQuery UI).
Examples:
/example/path#hash -> /example/path#secondHash = no router5 events
a[href="/example/path/#hash"] -> click = Router5 navigate, then re-attach hash
from router5.
I think that no matter what, when changing the hash of a URL, it will push to your history, and trigger popstate
events as well as hashchange
events. I am not sure how I would concile the two together.
from router5.
Well it currently already has the correct behavior, except for removing the hash when navigating to a URL or initializion.
You can see what I mean by going to https://hopspot.com and clicking the terms of use and privacy policy links.
from router5.
OK, so it needs to survive the router starting. What about navigation thereafter?
from router5.
That's why I had the idea of treating hash
as a special param name. So when navigating, if it's present in the navigate
call, it gets amended to the URL. This lets Router5 SPAs retain anchor linking.
from router5.
Is this feature something that you are considering? I have a use case similar to the above, where I'm using HTML5 mode + history and I'd like to use hash either as suggested above (special parameter) or as part of my route definition. E.g:
var routes = [
{ name: 'first', path: '/:first'},
{ name: 'first.second', path: '/:second'},
{ name: 'first.second.third', path: '/:third'},
{ name: 'first.second.third.hash', path: '#:hash'}
];
Specifying hash in routes was my initial idea, but after seeing what @JonathanWolfe suggested, I am happy with that too.
from router5.
I am considering it but I haven't got the time until now (this week and next week) to have some thinking about it. I'm not sure yet what I should support: preserving hash part of the URL, or introducing a hash parameter in route definitions.
from router5.
It's not covered by the v4 release. I think I know how to do it, I'm closing this issue for now as the solution only involves work on path-parser and route-node packages. I don't have a timeline yet on when I'll be able to support this.
from router5.
Sorry @troch for resurrecting this issue, but I was wondering if this bug will ever be fixed?
At the moment I have to do a lot of coding around browser plugin in order to preserve hashes:
- Ignore links that are on the same path, but have different hashes (i.e links to elements on page)
- Before calling navigate, save the new hash and do history.replaceState after transition end
- Add popstate listener before router5, save hash and do history.replaceState after transition end
Given that preserving hashes is the native behaviour of the browser, I don't see why router5 should be touching the, if useHash is false (I think everyone in this thread agreed to that)
If you will not be changing this behaviour, it would be good to know, so that I can fork the browser plugin and maintain it locally, which is preferable to writing code around it.
Thanks :)
from router5.
@dogoku it should preserve hash, but only on start. Are you talking about being able to navigate with a hash?
from router5.
Yes, the initial load is handled correctly.
My concern is during History Forward/Backward (i.e popstate), since the hash gets removed by the browser plugin.
Any clicked links, I handle in my app, so I am ok with preserving the hashes before calling navigate, as link click handling was never something the browser plugin did anyway.
from router5.
Related Issues (20)
- router5-plugin-browser base is case-sensitive
- TypeError of router5-transition-path HOT 2
- Unhandled promise rejection Error: Alias is already defined in route node in legacy Edge
- Integration(solid-js): reactivity of instance methods, getState vs subscribe's route, etc
- GitHub Pages and router5(+react) HOT 1
- Is non-latin letters are supported in the "path"?
- Remove the routes HOT 1
- Are arrays allowed as route params? HOT 1
- Improve type definitions
- Listeners plugin exposes incorrect typedefs HOT 1
- How to dynamically change base path on browserPlugin
- roadmap? HOT 2
- How can can pass query params to Link by react-router5? HOT 1
- Feature request on Navigation HOT 5
- BUG: errors handling unicode emoji
- QUESTION: Can I use the browser plugin but have each route specify when to use pushState vs replaceState? HOT 2
- Is this project abandoned? HOT 1
- There is an error in the areStatesEqual method
- Anyone interested to keep the package maintained? HOT 1
- cloneRouter() uses same root node
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 router5.