0

I have created routes like this

/home/display-cityname/

Right now I hardcoded all the city names I have and made different routes for all the cities, If I want to pass the city name dynamically, I can do something like this

/home/:cityname/

but I want that 'display' string to be appended for every city. Is there any approach where I can append the city name to that string itself? Something like this /home/display-{cityname}. I didn't find any solution where we can append a string to dynamic values in the route itself.

1 Answer 1

2

You can use a matcher: instead of "path" in the route properties, you do something like this:

export function displayCities(url: UrlSegment[]) {
  return url.length === 1 && url[0].path.startsWith('display-')
    ? ({consumed: url})
    : null;
}

export const routes = [{ matcher: displayCities, component: CityComponent }];

https://angular.io/api/router/Route#matcher

https://angular.io/api/router/UrlMatcher

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.