[AngularJS] Problem when loading routes from DB dynamically

2018-11-12 Thread Zlatko Đurić
The problem might be that your routes are not available at resolve time. You 
can go load the things later, but it doesn't matter any more, the router 
already failed.

You could put the router loader config into app initializer though. Then routes 
would get loaded before the app starts. Can't create an example for you on the 
phone, but Google got me here, looks good, you just need to adjust  it:
https://stackblitz.com/edit/angular-app-initializer-load-config?file=app%2Fapp.module.ts.

Alternatively, if this doesn't work for you, you can do tricks.
Step 1: Have a catchall route (`path: '**'`) that renders some dummy component 
("Loading, please wait...").
So if you go to root path, you get your app component, and if you go to 
anything else, you land here - and start loading router config.

Step 2: Add a bit of extra work to the loader, tell it to check the router 
state, and if you're at the dummy component, take the url and renavigate to it.

Hope those ideas can give you a hint.

Zlatko

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.


[AngularJS] Problem when loading routes from DB dynamically

2018-11-12 Thread Jose Cristhian Padilla Pinto
Hi guys, please your help with a problem I have. I'm loading routes from a 
DB through a web service and everything work as expected when using links 
to those routes. But when I refresh the page or I write directly the url in 
the adress bar the route does not work, why?

1) In the "app.component.ts" constructor I call a function that loads the 
routes

  async loadRoutes() {
await this.configService.cargarRutasMenu(() => {
  for (const item of this.configService._rutas) {
  this.router.config.unshift({ path: item.path, loadChildren: () => 
FormdinamicoModule });
  }
});
  }

2) Errors in the browser when trying to access the "testing" route

Router Event: NavigationStart
NavigationStart(id: 1, url: '/testing')
NavigationStart {id: 1, url: "/testing", navigationTrigger: "imperative", 
restoredState: null}
Router Event: NavigationError
NavigationError(id: 1, url: '/testing', error: Error: Cannot match any 
routes. URL Segment: 'testing')
NavigationError {id: 1, url: "/testing", error: Error: Cannot match any 
routes. URL Segment: 'testing' at ApplyRedirects.push../node_modules/@an…}
error: Error: Cannot match any routes. URL Segment: 'testing' at 
ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL 
Segment: 'testing'
Error: Cannot match any routes. URL Segment: 'testing'
...

Thank you very much.

Node: 8.12.0
OS: win32 x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package   Version
---
@angular-devkit/architect 0.7.5
@angular-devkit/build-angular 0.7.5
@angular-devkit/build-optimizer   0.7.5
@angular-devkit/build-webpack 0.7.5
@angular-devkit/core  0.7.5
@angular-devkit/schematics0.7.5
@angular/cli  6.1.5
@ngtools/webpack  6.1.5
@schematics/angular   0.7.5
@schematics/update0.7.5
rxjs  6.3.3
typescript2.7.2
webpack   4.9.2

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.