Angular 8 Default Routing

Discussão em 'Angular' iniciado por bjwhip, Outubro 16, 2024.

  1. bjwhip

    bjwhip Guest

    I have an app running Angular 8.2. The routing is working great, except for the default route.

    When going to website.com I want to be redirected to website.com/sign-in

    app-routing.module

    const routes: Routes = [
    {
    path: '',
    redirectTo: 'sign-in',
    pathMatch: 'full'
    },
    {
    path: '',
    component: PublicLayoutComponent,
    data: { title: 'Public Views' },
    children: PUBLIC_ROUTES
    },
    {
    path: '',
    component: PrivateLayoutComponent,
    data: { title: 'Private Views' },
    children: PRIVATE_ROUTES
    },
    ];


    public-routing.module

    export const PUBLIC_ROUTES: Routes = [
    {
    path: "sign-in",
    loadChildren: () =>
    import('../features/sign-in/sign-in.module').then(
    m => m.SignInModule
    )
    }
    ];


    private-routing.module

    export const PRIVATE_ROUTES: Routes = [
    {
    path: "dashboard",
    loadChildren: () =>
    import('../features/dashboard/dashboard.module').then(
    m => m.DashboardModule
    )
    }
    ];


    I have also tried adding this to the app-routing.module

    {
    path: '**',
    redirectTo: 'sign-in',
    pathMatch: 'full'
    },


    EDIT:

    All my routes work. When going to website.com/sign-in, angular looks at the app-routing.module then at the child routes to find where to route. If I add

    {
    path: '**',
    redirectTo: 'sign-in',
    pathMatch: 'full'
    }


    to the public-routing.module, anything except blank will redirect to sign-in. website.com/jdjhjdfjd will go to my sign in page, but website.com will not.

    Continue reading...

Compartilhe esta Página