razor icon indicating copy to clipboard operation
razor copied to clipboard

Allow @page directive in Razor Components to accept constant strings

Open hellfirehd opened this issue 2 years ago • 11 comments

Currently the @page directive must specify a route template. The route template must be enclosed in quotes and begin with the '/' character.

I need to be able to use a const string as well.

Is your feature request related to a problem? Please describe.

I want to define my routes in a single place and then reuse them throughout the application, eliminating as many string literals as possible. Without this, refactoring and long-term maintenance becomes a nightmare of Find/Replace.

Describe the solution you'd like

Ideal:

@page @ClientRoutes.Members.ClinicalSupervision

Acceptable:

@page "@ClientRoutes.Members.ClinicalSupervision"
public static class ClientRoutes
{
	public static class Members
	{
		public const string ClinicalSupervision = "/Members/ClinicalSupervision";
	}
}
...

private void CancelAsync() => NavigationManager.NavigateTo(ClientRoutes.Members.ClinicalSupervision);

hellfirehd avatar Aug 18 '21 17:08 hellfirehd