2
votes

I'm pretty new to Razor Pages, and I'm trying to figure out how to replicate routing I have in my current Angular Page.

I have a base razor page that will be populated with different data depending on which parameter is passed to it. This is easy enough, and I know how to do this. However, my problem is in the routing because I want to be able to pass a readable parameter that is based off of the base URL. For example, I want to be able to do:

https://myURL/Band1 https://myURL/Band2

and have both point to the same page (but not the Index Page), consume the parameter "Band1" or "Band2" to display the associated information.

I understand how to consume the parameter, and how to get data, what I'm not clear on is how to do this routing based on the base URL. I can see how I'd do it if it were https://myURL/b/Band1 since I'd make a "b" page and accept parameters.

But how does one do this without that intervening segment of the URL? I need to be able to do this to not break existing links.

Thanks!

1

1 Answers

1
votes

The docs for Razor Pages suggest you can create a page named Index.cshtml, which will act as the default where no page is specified in the URL.

Edit If you want to preserve the parameterless index page, but have your page take its place when the additional URL part is provided, try the following in your page:

@page "/{bandName}"