@Sayan751 hopefully you can help me with a question re router-lite
?
When we first set the app up we configure some common features implemented as Aurelia plugins. One of these starts an authentication flow, and once authenticated we register some additional plugins.
We have a root component which is set with Aurelia.app()
. This component has a getRouteConfig()
callback to configure the base routes. Before authentication, there is just a single starting route. What I’m trying to do is reload that root component after authentication and configuration of the additional plugins. For context, those plugins register IChildRouteConfig instances in the container, and when authenticated the root component resolves those routes and uses them to configure the router.
Can you suggest how I can trigger reactivation of that root component so that the getRouteConfig()
callback runs again?
I’ve also looked seen Multi root | The Aurelia 2 Docs but that doesn’t seem to work in the current beta.
I get the following on startup (this is caused by the Aurelia
dependency in LoginWall
)
Hi @simonfox! As the route configuration in router-lite is considered more-or-less static, the getRouteConfig
hook is invoked exactly once for any routed components. Your alternative with a multi-app root seems like a correct alternative.
Here I have prepared a simplistic POC: router-lite - multi-root POC - StackBlitz. The approach can be summarized as follows:
- This is event-based.
- After a successful login, an event is raised.
- The bootstrapping code (main.ts) sets up the login page as the initial root and wait for the authenticated event.
- Once the event is raised, it switched to other root.
Improvements:
- Naturally employ correct authentication flow.
- If using some kind of token persistence (that is, when the token is not only in memory at the client), the bootstrapping can check for that and conditionally set the login page as the initial root.
I hope this helps.
Awesome thanks @Sayan751 !
I was thinking of a solution like that but good to have confirmation that is a good approach.
I’ve submitted a PR to correct the current docs doc(multi-root): correct multi root scenario doc and link to example by simonfox · Pull Request #2127 · aurelia/aurelia · GitHub
1 Like