Home > Software design >  Angular child route redirect not updating the url path
Angular child route redirect not updating the url path

Time:10-26

I have the following route with a redirect for a child route but the URL path is not updated.

RouterModule.forChild([
            {
                path: '',
                component: MainComponent,
                children: [
                    { path: '', redirectTo: '/account/data', pathMatch: 'full',  },
                    {
                        path: "account", 
                        children: [
                            ...AccountPaths,
                        ]
                    },
                   
                ]
            },
            {
                path: '**',
                redirectTo: '',
                pathMatch: 'full'
            }
        ])

As you can see I redirect the default path '' to child route /account/data

The proper view is loaded but the /account/data is missing in the url

http://localhost:4200

instead (what I expect)

http://localhost:4200/account/data

My question is WHY?

CodePudding user response:

You can check all routing events, add tracing property on imports

RouterModule.forRoot(
  appRoutes,
  {
    enableTracing: false,
  }
)

CodePudding user response:

You did'nt show what's include inside your AccountPaths array. Is there another redirection maybe?

  • Related