Change URL of Razor Class Library page from client project

344 Views Asked by At

I created a Razor Class library (v6). In the RCL I have a page at ~/Pages/Page1.cshtml, which is accessible at /Page1.

But the RCL is for use in other projects, so I want a client project to be able to customise the path.

For example, how can a client project change that to /Foo/Page1?

1

There are 1 best solutions below

0
lonix On

This is a working but NON-IDEAL solution.

In the client project:

services.AddMyRclProject("/Foo/Page1");

In the RCL project:

public static void AddMyRclProject(this IServiceCollection services, string customRoute){

  services.AddRazorPages(x => {
    x.Conventions.AddPageRoute("/Page1", customRoute);
  });

}

This works, but both routes are active:

/Page1
/Foo/Page1

It's unclear how to remove the original one.

I'm leaving this question open. If you have a better way, add your answer and I'll accept it.