razorrazor-3

Is it possible to match all subdirectories by a PageRoute or convention in Razor pages?


I'd like to use same page for all subdirectories in Razor pages. I have this in startup:

services.AddRazorPages(options =>
{
  options.Conventions.AddPageRoute("/test", "{path?}");
});

But this only matches first subdirectory, such as test/my. Is it possible to match "test/my/many/wishes" and similar requests?

I'd like to avoid url rewriting, as I think using the routing approach then also helps with link formatting etc.


Solution

  • I know, it's a basic one. But I couldn't find it at first - here it is for root:

    options.Conventions.AddPageRoute("/index", "{*url}");
    

    https://www.learnrazorpages.com/razor-pages/routing