不要在 Blazor Server 应用程序中的某个配置中包括所有 @page。

huangapple go评论63阅读模式
英文:

Don't include all @page for a certain configuration within Blazor Server app

问题

有没有办法我可以控制何时在 Blazor 服务器应用程序中添加 @page 指令?

例如,假设我只希望页面 /Test 在 DEBUG 配置中包含,而不在 release 中包含。

我已经尝试在 .razor 文件中使用 #define 指定编译器指令。

英文:

Is there anyway I can controll when to add a @page directive within a Blazor server app?

For example lets say I want the page /Test only be included within DEBUG configuration but not in release.

I've already tried specifying compilere directives with #define within the .razor file.

答案1

得分: 2

I've already tried specifying compilere directives with #define within the .razor file.

And that won't work. But you can apply #if in a .razor.cs file. So you need to create the code behind file first. (type Ctrl+. on the @code tag)

And then:

#if DEBUG
    [RouteAttribute("/fetchdata")]
#endif
    public partial class FetchData
    { 
       ...

@page("<path>") becomes [RouteAttribute("<path>")]

英文:

> I've already tried specifying compilere directives with #define within the .razor file.

And that won't work. But you can apply #if in a .razor.cs file. So you need to create the code behind file first. (type Ctrl+. on the @code tag)

And then:

#if DEBUG
    [RouteAttribute(&quot;/fetchdata&quot;)]
#endif
    public partial class FetchData
    { 
       ...

@page(&quot;&lt;path&gt;&quot;) becomes [RouteAttribute(&quot;&lt;path&gt;&quot;)]

huangapple
  • 本文由 发表于 2023年6月1日 14:41:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76379278.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定