Remove magic string for razor component @page routing
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
In the Blazor and Razor Pages components we are specify the route like:
@page "/this/is/my/route"
These magic string are not desirable in a modern programming context. And also it become difficult to manage because of duplication - good probability you must write it somewhere else also, and now you have two magic strings… for every route.
Describe the solution you’d like
Please can we have no magic string for something so important like routing?
Additional context
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
[Feature Request] Remove magic strings from RazorPages ...
A RazorPages route can be defined like this: @page "/Foo" But ... [Feature Request] Remove magic strings from RazorPages routing #41930.
Read more >Avoid magic string in ASP.NET Core attribute routing
I can avoid magic strings for areas, controllers, actions by using the special tokens [controller] , [action] , etc. This is a simple...
Read more >Localising the DisplayAttribute and avoiding magic strings ...
In this post, we cover some of the problems you may find when localising your application such as localising the DisplayAttribute and broken ......
Read more >ASP.NET Core Blazor routing and navigation
This article explains how to manage Blazor app request routing and how to use the NavLink component to create navigation links.
Read more >Blazor Power Hour: Razor Class libraries and Shared Routing
Today on the #Blazor Power Hour. We'll look at Razor Class libraries and routing from dependent assemblies. The stream starts at 02:27, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Something like that is good
There many ways to do this, anything you choose is better to magic strings.
Not the author but have come across this issue a few times. Especially updating all nav-links to the pages when a part of the route changes is my biggest issue i have here.
Ideally you could just use any const string that is known at compile time. For example using a static helper class holding the strings:
and then use string interpolation in the actual route
Or you use the constant for the complete route
Then you could easily link to these pages
And not worry about changing your Route.