Router - Use routes from a rest service

Hi,

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?

Thanks in advance.

I was doing something similar and used a redirect to avoid the display of a route that was no longer avail

in app.js

  configureRouter(config, router) {
    config.title = 'EPC Kiosk';
    config.map([
      { route: ['', 'out-of-service'], name: 'out-of-service', moduleId: PLATFORM.moduleName('./out-of-service'), nav: true, title: 'Out Of Service' },
      { route: ['testing'], name: 'testing', moduleId: PLATFORM.moduleName('./testing'), nav: false, title: 'Testing' }
    ]);
    config.mapUnknownRoutes({ redirect: '' });
    this.router = router;
  }

There’s a few of ways you could work this out.

  1. 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).
  2. 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.
  3. In your app.js add some pipes to your routes to manage auth…http://aurelia.io/docs/routing/configuration#pipelines
1 Like

— LoOL —

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… -.-’

Thanks again guys!