I am looking into the possibility for Angular 8 to dynamically create the routing from a REST service. This idea is that a user can create pages which should be available for access by routing on the web page.
I have seen options to dynamically add routes, however I would like to have the routes loaded before the rest of the app, so that when a user would access: 'website/generatedPage' the routing is in place before the app is fully loaded.
How do I make sure the routes from the REST service are in place before the app continues with the routing options?
The following piece of code adds the routing to late:
constructor(
private sitemapService: SitemapService,
private router: Router
) {
this.sitemapService.getSiteMap().then(result => {
result.forEach(sitemapItem => {
this.router.config.push({ path: sitemapItem.pageName, component: PageComponent });
});
});
}
With this code you can navigate to the page when the app is aready loaded, however, when you would directly request the route, it is not loaded yet.
Thank you in advance!