-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support hash router #6
base: main
Are you sure you want to change the base?
Conversation
index.js
Outdated
let router = atom() | ||
let isHashRouter = options && options.hash; | ||
|
||
let locationPathname = isHashRouter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s rename variable
I am not sure that this is a right API. Often, hash navigation is independent of route’s navigation. For instance, I use hash navigation for popups, which can be open on every page. In your suggestion I need to manually describe all possible hashes in URL schemas which is not useful. |
What API is preferable for you? Do you want to have the possibility of using both schemas? |
c3349e9
to
cb63cd5
Compare
It is a question for you. This task not just about writing a code, but about creating API (something like product manager work but for open-source library). |
Well, this was exactly what I was looking for. When the application is the resource the URL is locating, it makes sense to use hash routing as pointers to internal views (not to be confused with state). To get it to recognize routes I did need to change lines 7-9 to: let getPathname = isHashRouter
? () => location.hash.replace(/^#/, '')
: () => location.pathname When it stripped out the leading slash, that lead to route recognization failure... Maybe because I defined my routes with the leading slash, now I think about it. Anyway, thanks for this patch, it's been very useful for me! |
Another use case for hash routing is when your app is distributed via some object store like AWS S3. You can set your CDN to route While there are more robust solutions to this problem like configuring the store to redirect 404s back to your index.html... hash routing is a simple solution as well. Hash routing ( While I'll admit I wouldn't want to use this solution for anything too serious, it's a quick and dirty way to host a webapp. |
#3