zilch / type-route

The flexible, type safe routing library.
https://type-route.zilch.dev
MIT License
423 stars 15 forks source link

Support for "hash routing" #31

Open Retsam opened 4 years ago

Retsam commented 4 years ago

Does this package have any way of supporting hash-based routing - i.e. routes like app.com#foo/bar instead of app.com/foo/bar? react-router supports this use-case with a HashRouter.

It doesn't appear that there's any support for this "out of the box", is there any way to build it with the tools this library provides? I love the API, but we need to use hash routes for legacy reasons, and that seems like it might end up pushing us back to using react-router.

bradenhs commented 4 years ago

In theory this should be relatively easy to add support for but you're correct in saying there isn't any support for this presently. The hardest part will likely be figuring out the right way to expose this feature via the Type Route api since there isn't an options object you can pass into createRouter right now (not that we can't do that - just need to think about it a little harder than we'd have to otherwise). The other potentially sticky bit on the implementation side will be exactly how this fits into the server-side rendering story. Thanks for posting this though! There are some reasonably large api changes coming down the road to support more use cases and I'm putting together a roadmap now to plan out how everything will fit together. I think this issue is likely important enough to merit inclusion in that roadmap.

devdoomari3 commented 4 years ago

there's already a configuration option inside history.configure(config: HistoryConfig)

or is that API supposed to be hidden?

bradenhs commented 4 years ago

That api will soon be deprecated. ~The next version of Type Route is batching together a bunch of suggested improvements that have been made over the course of the last year and providing first class support for hash routing is one of them.~ You can checkout the progress on the next branch here: https://github.com/type-route/type-route/pull/35. The next release of Type Route is going to be a big step towards v1 of the library and moving out of the beta phase. Any feedback on the changes being made would be appreciated!

bradenhs commented 4 years ago

Unfortunately the latest version of the library Type Route depends on for manipulating browser history (https://github.com/ReactTraining/history/releases/tag/v5.0.0) no longer supports hash history without more advanced browser APIs :( I'm still open to making this possible in Type Route but it is going to be more difficult than initially imagined.

bradenhs commented 1 year ago

All modern browsers support the history API https://developer.mozilla.org/en-US/docs/Web/API/History#browser_compatibility. I don't think the need for hash routing is compelling enough to pursue this any longer.

elektronik2k5 commented 1 year ago

@bradenhs my personal use case for hash routing isn't about browser compatibility at all. Perhaps it is a matter of misleading terminology: I don't need to be able to use hash routing as a replacement of the history API. I want to be able to use hash fragments like query strings and utilize both simultaneously: /some/path?query=params&go=here#while=hash&params=go-here. The use case is about having the flexibility to handle both (in a typesafe manner, of course), where hash routing is an optional (and possibly volatile) part of the routing scheme.

This is useful for managing nested sub-navigation. For example, if we have a /people/person-id path, within which we can navigate to sub-resources of the person, like contacts or addresses, within which we can focus a specific record like so: /people/person-slug?contact=person-slug#address=address-slug, which would look like /people/alice-in-wonderland?contact=bob-the-builder#address=home-away-from-home.

bradenhs commented 1 year ago

Gotcha! Makes sense. I probably won't personally make a move to support this in the near future but would be happy to look at any PRs.