From what I understand from Angular2 router documentation, the routes config default pathMatch strategy is "prefix", "prefix" pathMatch strategy means the the app router only needs to look on the start of the url and match it with the proper route.
Reference: https://angular.io/docs/js/latest/api/router/index/Routes-type-alias.html#!#matching-strategy
That been said, with the below configurations I would assume that this route should load ExampleComponent
if I navigate to /abcdefg
.
One problem that this is not working, am not sure what is wrong and i cant find much information about this on google or in @angular/router
source code.
Thank you for your help.
const ROUTES: Routes = [
{ path: '', component: MainLayoutComponent, pathMatch: 'prefix', canActivate: [AuthGuard], children: [
{ path:'abc', pathMatch: 'prefix', component: ExampleComponent},
{ path: '', component: HomepageComponent }
]},
];
export const ROUTING = RouterModule.forRoot(ROUTES, { useHash: false });
Update #1, Trying Günter Zöchbauer suggestion.
new router configurations are:
now /abc/defg
works but not /abcdefg
{ path:'abc', pathMatch: 'prefix',
children: [
{ path:'**', component:ExampleComponent},
]
}
abc/de
works, but notabcde
, i'll update the question now to show you the new configurations. – Anas Al Hamdan Oct 10 '16 at 8:42abc/de
but not withabcde
. In praxispathMatch
is only to decide if the route matching algorithm should continue searching with an empty path on child routes when''
already matched on the parent route. This is a special case because it's hard to now if "nothing" should be consumed when it matches or not. I don't know of other use cases forpathMatch
. – Günter Zöchbauer Oct 10 '16 at 8:50