I’m trying to define the AppRouter with the routes provided from a request to the back-end.
The idea is to return only the routes which the logged user has access.
What is the best way to do this, or where is the best place to do the request of those routes?
I was trying to do that in the app.js but the problem is that, if I refresh the page the router shows that the page doesn’t exist because the request hasn’t finished… -.-’
Can anyone give me some instructions about this? anyone tried something similar?
Making an XHR call inside your main.js to preload a singleton and inside your done promise just fire off aurelia.start(). Then in your app.js just refer to your singleton route loaded object (or a custom service).
Load them all like @heybignick suggests and then you can create an auth service that you can then use on your canActivate() viewmodel lifecycle method (see http://aurelia.io/docs/plugins/dialog#lifecycle-hooks). This would also allow for a better end user experience if they didn’t have access since you can redirect them to another appropriate page. With this method you could also make a base viewmodel class that you extend on your routed viewmodels that would handle authorization.
Turns out that, I could simply make the fetch inside the configureRouter and return its promise…
I thought was the first thing that I tried and didn’t work… -.-’