How do I configure my razor page to accept multiple routes? For example, if I have a razor page ./Pages/Inovices/Overview.cshtml. I need this page to handle requests for ~/invoices AND ~/invoices/overview. Currently I'm using Handler methods on an Index.cshtml but it feels like there should be an easier way. Any thoughts?
You can add a convention for your page, using AddPageRoute
. Here's what it would look like for your example:
services.AddMvc(...)
.AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/Invoices/Overview", "invoices");
});
This adds a new route for the page but also keeps the existing route as is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With