How create a route in Angular where a parameter is within X possible values

Discussão em 'Angular' iniciado por Conde, Setembro 23, 2024.

  1. Conde

    Conde Guest

    I'm trying to create a route in Angular where a parameter is within X possible values. I'm trying it with a matcher in the routes:

    {
    path: '',
    component: DefaultComponent,
    canActivate: [AuthGuard],
    children: [
    {
    path: '',
    component: CountryLandingComponent,
    pathMatch: 'full',
    },
    {
    matcher: (url) => {
    if (url.length > 0 && (Object.values(COUNTRIES_SLUGS) as string[]).includes(url[0].path.toLowerCase())) {
    return {consumed: url, posParams: {[COUNTRY_SLUG_PARAM]: new UrlSegment(url[0].path, {})}};
    }

    return null;
    },
    component: CountryProviderComponent,
    children: [
    {
    path: '',
    component: SearchIndexPage,
    pathMatch: 'full',
    },
    {
    path: 'houses',
    loadChildren: () =>
    import('../modules/houses/houses.module').then((m) => m.HousesModule),
    },
    {
    path: 'outing',
    loadChildren: () =>
    import('../modules/outing/outing.module').then((m) => m.OutingModule),
    },


    ....

    export enum COUNTRIES_SLUGS {
    country1 = 'country1',
    country2 = 'country2'
    }

    export const COUNTRY_SLUG_PARAM = 'country-slug';


    However, routes like https://platform.docker.vm:4201/country1/houses/924/view are not being activated, and they were activated fine without using the route matcher. Can someone help me?

    Continue reading...

Compartilhe esta Página