Search code examples
angularroutesangular-routing

Angular 7 - how to check if the user directly navigate into the page


I have an app with the next routing structure:

{
    path: "home",
    component: HomeComponent,
    children: [
        {
            path: "list",
            component: ListViewComponent
        },
        {
            path: "dashboard",
            component: DashboardComponent
        },
        {
            path: '',
            pathMatch: 'full',
            redirectTo: 'dashboard'
        },
        {
            path: "**",
            redirectTo: 'dashboard'
        }
    ]
}

how I can check if the user navigates into the page by full path eg home/list or by redirectTo?


Solution

  • You can check the url by adding:

    path: 'team/:id',
    component: TeamComponent,
    canActivate: ['canActivateTeam']
    

    Here ['canActivateTeam'] can be a function in a service.