0

I have a dependency on fetching a remote JSON config data prior to any routes. What is the recommended way to do so?

Is a guard the recommended way?

Steve
  • 53,375
  • 33
  • 96
  • 141

1 Answers1

1

No, guards are for restricting route access to user roles - e.g. guest/customers/admins/etc.

You can use the router.resetConfig() function to change the routes after the initial load. So, you could load the app with a default empty root, then after you've fetched your json, resetConfig() with the new routes.

For example:

        let rc: RouterConfig = [
            { path: 'xyz', component: Test },
            { path: 'abc', component: Test },
        ];
        router.resetConfig(rc);
Andy-Delosdos
  • 3,560
  • 1
  • 12
  • 25