[AngularJS] Dynamic routes not available when refreshing page or typing the url in the address bar

2018-11-12 Thread Jose Cristhian Padilla Pinto

Hi guys, please help with a problem, I'm loading my routes from a database 
through a web service. Once the page is loaded I can access all the routes 
using the links in the page and all works as expected. The problem is that 
those routers are not working when refreshing the page or typing directly 
the url in the browser's address bar.

a) To load the routes i use:
this.router.config.unshift({ path: item.path, loadChildren: () => 
FormdinamicoModule })

b) the routes are loaded in the app.component.ts constructor.

c) error in the browser for 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…}
core.js:1673 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.

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