简体   繁体   English

在 Blazor Wasm 中创建自定义路由

[英]Create Custom Route in Blazor Wasm

I am using blazor wasm, I want to create a custom routing that starts with the letter @ and ends with the User's username.我正在使用 blazor wasm,我想创建一个以字母 @ 开头并以用户用户名结尾的自定义路由。 I wrote the following code, but it seems that the routing cannot be set this way我写了以下代码,但是好像不能这样设置路由

the route I expect https://localhost:5000/@michel我期望的路线https://localhost:5000/@michel

@page "/@{Username}"

@code {

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

}

You can't segment routes with ascii characters.您不能使用 ascii 字符对路线进行分段。 "@" is just an ascii character. “@”只是一个ASCII字符。 So:所以:

https://localhost:5000/@michel

looks for a route "@michel", and will only find one if you have this on a page:寻找路线“@michel”,并且只有在页面上有此路线时才会找到:

@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.如果您想使用“@”作为特殊字符(如“/”)进行路由,那么我相信您正在构建自定义路由器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM