Skip to content
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

Hash routing #3

Open
AndreiEres opened this issue Sep 15, 2021 · 8 comments
Open

Hash routing #3

AndreiEres opened this issue Sep 15, 2021 · 8 comments

Comments

@AndreiEres
Copy link
Contributor

Developing chrome extension I realised that I can't use nanostores for routing because it doesn't use hash.

Are there any plans to add hash routing?

@ai
Copy link
Member

ai commented Sep 15, 2021

I believe that URL router and hash router should be separated.

I, personally, use hash router for popups.

We can add extra hash router to this package. Do you have an idea of what it should do?

@AndreiEres
Copy link
Contributor Author

AndreiEres commented Sep 17, 2021

Do you have an idea of what it should do?

I think it should parse url params #/pages/:page.

Maybe also we should ever set hash to #/ as default, because it's root.

@ai
Copy link
Member

ai commented Sep 17, 2021

I think it should parse url params #/pages/:page.

It will not fit my case, when I have list of popups. We can use a different hash routers for different use cases. Like createHashPageRouter and createHashListRouter.

BTW, why do you use #/… page routing instead of using the real URL?

@AndreiEres
Copy link
Contributor Author

AndreiEres commented Sep 17, 2021

It will not fit my case, when I have list of popups. We can use a different hash routers for different use cases. Like createHashPageRouter and createHashListRouter.

What do you mean? How it looks?

BTW, why do you use #/… page routing instead of using the real URL?

Hm, I think it doesn't work on extension popup.

In my case I just added new store subscribed to hash changes and parsed last param from url. It's quite enough for small cases.

@ai
Copy link
Member

ai commented Sep 17, 2021

What do you mean? How it looks?

I use hash to store data about current opened popups like #userPopup:userId,confirm:delete:userId.

In my case I just added new store subscribed to hash changes and parsed last param from url. It's quite enough for small cases

Yeap, I like the idea.

createHashStore(hash => parseHash(hash))

It could work for both our cases.

@JulianCataldo
Copy link
Contributor

JulianCataldo commented May 9, 2023

Hello there,

I've not digged yet into the code regarding encode/decodeURI stuff, and maybe I should open a separate issue for this?

I put this here because my need it's kind of interlaced with this present issue.
Would be cool to have a catch-all params like:

const routes = {
  home: "/home",
  content: "/content/:path?",
} as const;
# Currently:
http://localhost:5173/content/%2Ftest_repo_1%2Fmain%2Fdocs%2Fllasslaa1683544785369.md

# Would like:
http://localhost:5173/content/test_repo_1/main/docs/llasslaa1683544785369.md

# Or maybe with opt-in hash routing, if possible?:
http://localhost:5173/content#/test_repo_1/main/docs/llasslaa1683544785369.md

I'm not sure about allowed characters inside URL, after hash or search params…
Rules seems pretty wild.

Inspiration: Stoplight Elements or Redoc Redocly are offering all sort of routing options (dynamic path segments or hash).

Thanks for hearing me!

@ai
Copy link
Member

ai commented May 10, 2023

@JulianCataldo yes, it should be a separated issue (and very likely that I will need a PR for this)

@jqueryisamonad
Copy link

jqueryisamonad commented Jul 6, 2023

BTW, why do you use #/… page routing instead of using the real URL?

I embed small svelte apps in php pages. In this case I just can't use real URLs. It would be great to have a fully functional hash page router.

No pressure on maintainers, just describing one more use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants