Closed maliiiith closed 5 years ago
You’re on the right track! I do something similar in my current app. The main difference in my approach is I pass the currentUser to context, and call navigation.setContext to update it when it changes (which recomputes the routes).
Let me know if this helps.
@jamesknelson that is interesting. Will the routes that earlier was mounted, be unmounted? Or what happens at setContext? Is it that of 'restting' the routes as you explain in the documentation of not trying to change the context to often?
Changing the context will just recompute the route
object from scratch. You can think of this as calling a setState
within the <Router>
function - it can be very fast, or quite slow depending on the size and design of your application.
In any case, authentication state changing should be a relatively rare event, so it shouldn't be a problem to call setState
when auth state changes.
@jamesknelson cool cool thanks! Is there a difference from setContext, and changing the object that is sent in to the context of the router? As you mention here: https://frontarm.com/navi/en/guides/routing-context/#the-context-prop that if the object changes a new computation changes.
They're actually the same thing. Changing the context
prop just calls setContext
under the hood.
Kkk, then I understand more :) Thanks. I will let @malithrw close this when he is done with examples and understood it himself
Thanks guys!
I'm trying out Navi on a ReactJS application that has a bit complex routing system. What I'm doing right now is having a wildcard route, and then do necessary permissions checks and then mount routes based on the checks.
But with this approach I'm unable to unmount routes if the user loses permissions (when logging out).
Do you have an example similar to what I'm trying to do right now?