0

App routes:

[
    { path: '', loadChildren: './layout/layout.module#LayoutModule', canActivate: [AuthGuard] },
    { path: 'login', loadChildren: './login/login.module#LoginModule' },
    { path: 'dashboard', loadChildren: './layout/layout.module#LayoutModule' },
    { path: 'error', loadChildren: './server-error/server-error.module#ServerErrorModule' },
    { path: 'access-denied', loadChildren: './access-denied/access-denied.module#AccessDeniedModule' },
    { path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' },
    { path: '**', redirectTo: 'not-found' }
]

LayoutModule Routes:

   [{
        path: '',
        component: LayoutComponent,
        children: [
            { path: '', redirectTo: 'dashboard' },
            { path: 'allcookies' , loadChildren: './allcookies/allcookies.module#AllcookiesModule' },
            { path: 'dashboard', loadChildren: './dashboard/dashboard.module#DashboardModule' },
            { path: 'details', loadChildren: './details/details.module#DetailsModule' },
            { path: 'domains', loadChildren: './domains/domains.module#DomainsModule' },
        ]
    }]

I have DetailsModule routes coniguration like this,

[
  { path : '' , redirectTo: 'email-details' },
  { path : 'email-details' , component : EmailDetailsComponent },
  { path : 'email-details/:email_id' , component : EmailDetailsComponent },
  { path : 'email-details/:email_id/:curr_page' , component : EmailDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page/domains/:user_id/:domain_page' , component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page/domains/:user_id' , component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page' , component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id' , component : FingerprintDetailsComponent },
  { path : 'fingerprint-details' , component : FingerprintDetailsComponent }
]

I have given url

http://localhost:4302/details/fingerprint-details

But it os redirecting to

http://localhost:4302/details/email-details/fingerprint-details

1
  • None of the routes shown above start with details. Are these the only routes in your application? Commented Feb 8, 2018 at 13:55

2 Answers 2

1

In the redirectTo property, you should write the absolute path from the route level. I also always use pathMatch: 'full' in all of my routes to be sure I will not have relative path involved.

Test it with that configuration:

[
  { path : '' , redirectTo: '/email-details', pathMatch: 'full'},
  { path : 'email-details' , pathMatch: 'full', component : EmailDetailsComponent },
  { path : 'email-details/:email_id' , pathMatch: 'full', component : EmailDetailsComponent },
  { path : 'email-details/:email_id/:curr_page' , pathMatch: 'full', component : EmailDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page/domains/:user_id/:domain_page' , pathMatch: 'full', component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page/domains/:user_id' , pathMatch: 'full', component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id/:fp_page' , pathMatch: 'full', component : FingerprintDetailsComponent },
  { path : 'fingerprint-details/:fp_id', pathMatch: 'full', component : FingerprintDetailsComponent },
  { path : 'fingerprint-details' , pathMatch: 'full', component : FingerprintDetailsComponent }
]

Here's the corresponding link to the doc: https://angular.io/guide/router#redirecting-routes

0
0

Quentin beat me to it.

https://angular.io/guide/router

"A redirect route requires a pathMatch property to tell the router how to match a URL to the path of a route. The router throws an error if you don't."

Not the answer you're looking for? Browse other questions tagged or ask your own question.