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
'*' wildcard #60
Comments
It's not possible right now, but it'd be a simple enough addition. The only thing that would need to be changed is to add a special case https://github.com/frontarm/navi/blob/master/packages/navi/src/Mapping.ts#L59 Would you be interested in submitting this is a PR? |
Sure I'd love to. I have some questions though, would the '*' wildcard just short circuit the |
So The special thing about '*' is that it would gobble up '/' characters, which no other patterns can do, so it would probably be easiest to just special case it at the top of the function. |
@cevr Just curious, why the need for a Because of it's compostability you can even |
Say you have a few routes that you want to be available without auth (e.g. I think you raise an interesting point though -- this does feel more natural to me: compose(
mount({
'/login': route({
view: <div>Login</div>,
}),
'/': redirect('/login'),
}),
// Fall back to this if no route was found in the `mount()`
map((req, { user }) => (user ? protectedRoutes : redirect(req.originalUrl))),
) Looking at this though, I've realized an issue with both this approach and the Currently, it's possible to recursively look through all the patterns of a |
Nearly impossible right? Haha. What if some convention and helpers were exposed so 1.) this pattern would be easier/more obvious to implement and 2.) we could infer that they are not requiring auth for a few routes and are for the rest. I'm not sure if that's even possible 🤹♂️, apologies if it's way off base. |
@jamesknelson I see what you mean. I think I ran into that problem while trying to do a workaround method (site map not detecting other routes). Perhaps the better solution would be to mount different routes at the root index.js, though I haven't tried it. Thoughts? const bootstrap = user => {
const routes = user ? protectedRoutes : unprotectedRoutes;
register({
routes,
exports: {
App,
},
async main() {
let navigation = Navi.createBrowserNavigation({ routes });
navigation.setContext({ user });
await navigation.steady();
let hasStaticContent = process.env.NODE_ENV === 'production';
let render = hasStaticContent ? ReactDOM.hydrate : ReactDOM.render;
render(
<NaviProvider navigation={navigation}>
<App />
</NaviProvider>,
document.getElementById('root'),
);
},
});
};
getUser().then(bootstrap) |
What if the user signs in or out? How would you re-render the whole app? Reload the page? Seems like this could be solved without re-mounting everything. |
The way I currently do this is to just protect routes one at a time; so instead of wrapping a You could even create a custom I'm currently putting together an example using firebase for auth, and hope to have it done this weekend. That would probably be the best way for me to demonstrate.
I've been thinking about this and I think it should still be possible by using custom headers or a custom HTTP method. E.g. use |
This is currently blocked by #64. Once the new site map generation is done, wildcards or mount composition should become an easy change. |
Just an update on this: we're going to have to go with wildcards instead of mount composition, as mount composition is incompatible with react-router style |
Have just pushed wildcard support, will be part of the next release. |
I can't seem to find this in the docs, but is it possible to route with a '*' wildcard that acts as a middleware?
Example:
The text was updated successfully, but these errors were encountered: