Create Custom Route in Blazor Wasm

Viewed 91

I am using blazor wasm, I want to create a custom routing that starts with the letter @ and ends with the User's username. I wrote the following code, but it seems that the routing cannot be set this way

the route I expect https://localhost:5000/@michel

@page "/@{Username}"

@code {

[Parameter]
public string Username { get; set; }

}
1 Answers

You can't segment routes with ascii characters. "@" is just an ascii character. So:

https://localhost:5000/@michel

looks for a route "@michel", and will only find one if you have this on a page:

@page "/@michel"

Put in a separator like this:

@page "/@/{UserName}"

and that will work.

If you want to route using "@" as a special character (like "/") then I believe you're into building a custom router.

Related