nanostores/router

Hash routing

AndreiEres opened this issue · 8 comments

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 commented

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?

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 commented

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?

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 commented

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.

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 commented

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

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