Search code examples
angularangular-routingangular7angular-router

Angular7 using menu to activate route works but copy-pasting any route redirects to homepage no matter what


I've been comparing with another angular6 project that I have side-by-side and I can't tell of any other difference than using the 'sidenav' navigation. I am keeping the router-outlet in app.component inside the sidenav container but I also took it out of there and to the top of the file to make sure it is not the culprit.

If I use the normal navigation to go to a certain component/route even with route parameters all works great.

The moment I'm trying to navigate to a link, it redirects to the homepage and router-outlet doesn't even load the 'home' component.

My routing module code:

const routes: Routes = [
      {
        path: 'admin-panel/:resource',
        component: AdminPanelComponent,
        canActivate: [AdalGuard, TenantGuard]
      },
      { path: '', component: HomeComponent, canActivate: [AdalGuard] },
      { path: '*', component: NotFoundComponent, canActivate: [AdalGuard] }
    ];

    @NgModule({
      imports: [RouterModule.forRoot(routes)],
      exports: [RouterModule]
    })
    export class AppRoutingModule {}

Solution

  • Not necessarily the solution but in my specific case, this was happening because of the Guard I wrote as the canActivate which just needed to be rebuild from scratch, there's no debugging that thing.

    EDIT:

    Actual solution, I was using path: '*' instead of '**' for the notfound component.