Angular router '**' wildcard as a trick with child routes? Using the latest 2.4.0 and Router 3.4.1

I experimented with dozens of configurations trying to get this to work, but can't figure it out.

The specified url is as follows:

anything and otherthing can literally be anything.

The route configuration I was hoping for would work, but would ultimately take on specific routes where https://domain.com/profile would call catchall ('**'), which seems very strange, as far as I understand catchall should only start or catch routes that are not defined above:

Where app.module has the following:

 export const routes = [ { path: '', loadChildren: 'app/dashboard/dashboard.module' }, { path: 'profile', loadChildren: 'app/profile/profile.module' }, { path: '**', loadChildren: 'app/anything/anything.module' } ]; @NgModule({ imports: [ BrowserModule, RouterModule.forRoot(routes) ], declarations: [AppComponent] bootstrap: [AppComponent] }) export class AppModule {} 

Where anything.module has the following:

 const routes = [ { path: ':id', // hoping to pick up the wildcard as param this way component: AnyComponent, children: [ { path: 'edit', component: EditComponent } ] } ]; @NgModule({ imports: [ CommonModule, RouterModule.forChild(routes) ], declarations: [ AnyComponent, EditComponent ] }) export default class AnythingModule {} 

In any case, so that the above use case works with Angular Router 3.4.1?

+7
angular angular2-routing
source share
2 answers

If the ProfileModule does not have a path: '' route, then there is no route to map, and the router continues to match the remaining routes.

0
source share

This was requested a year ago. However, I used Angular 5.1.2 and ended up with the same problem

This was a bug with the router allowed at release # 18139 , I upgraded to 5.2.1 on my .json package to get the fix

 "@angular/core": "^5.2.1", "@angular/forms": "^5.2.1", "@angular/http": "^5.2.1", 

etc...

0
source share

All Articles