Allow for custom hash/dynamic root
Use case: locale in URL I'd like to be able to keep my locale in the URL so that any sharing/bookmarking of the URL retains the locale that the user is viewing the page in.
I would assume the way to do that would be some kind of dynamic root (splat? dynamic segment?) or by adding the locale in to the hash (e.g. http://myurl.com/en/page or http://myurl.com/#en/page). I guess this would mean the router would need some kind of internal state that means any Links or transitionTo calls would know what the dynamic root should be. Could that be derived from the current url?
Forgive me if I'm missing something or if I've posted this incorrectly - this is my first issue on GitHub.
Thanks!
You can put that param in the path of the root route.
<Routes>
<Route path="/" handler={RedirectToDefaultLocale} />
<Route name="app" path=":locale" handler={App}>
<Route name="user" path="users/:userId" handler={UserHandler} />
</Route>
</Routes>
var RedirectToDefaultLocale = React.createClass({
statics: {
willTransitionTo: function(transition) {
transition.redirect('app', {locale: 'en'});
}
}
});
// in App and UserHandler, and everything else, locale will be available on
// `this.props.params.locale`, pass it into your `Link`s and everything else.