Skip to content

Clarify Blazor Web Route behavior #52176

@Kumima

Description

@Kumima

Is there an existing issue for this?

  • I have searched the existing issues

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

For Global Auto Interactive Prerendered Template:

Although this seems by design, it still feels inconvenient.

Related Question:

Is there a better way to provide SSR with global auto interactive enabled, better than checking the request?

<Routes @rendermode="@RenderModeForPage" />
@code {
    [CascadingParameter]
    private HttpContext HttpContext { get; set; } = default!;

    private IComponentRenderMode? RenderModeForPage => HttpContext.Request.Path.StartsWithSegments("/Account")
        ? null
        : InteractiveAuto;
}

Investigation:

Related #52063
AuthorizationMiddleware redirect takes higher priority then NotAuthorized cotent.
Related #46980, #48983, #51411, #51847.

I just met a similar problem with #51203.
@danroth27
Only If the router render mode is set as null, which means SSR, it will shows StatusCode.razor permanently. Your mentioned plain text "Not found" seems to still come from the depreciated Not Found component. The flicker seems caused by Prerendering. During the prerendering, the "/test" route request is ReExecute to "/StatusCode/404". After the interactive is ready, "/test" goes through the Router component, which results a "Not found".

The issue #48983 also mentioned

If you don't have an interactive router, then a navigation to a nonexistent URL will return a 404 from the server, and then: If you have enhanced nav enabled (default) then you'll see Error: 404

I'm confused about where the "Error: 404" comes from.

To make a rarer scenario, and there is another similar issue #51847:
For global auto, the Router component is under the client project to make it able to be rendered as auto. Normally, we placed the pages in the Client project. The AppAssembly of Route is set as Client, so it can discover pages defined in Client project.
Define a page in Server project, let's define it as "/test". If we route to the "/test", the browser will flicker. It first renders the test component and then it shows plain text "Not found". The first is because of Prerender. This causes more confusion: it flickers the content and then renders the "Not Found".

Static and prerender discovery comes from below which includes the pages defined in Server project.

app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(Client._Imports).Assembly);

Interactive discovery comes from another which only includes the pages defined in Client project.

<Router AppAssembly="@typeof(Routes).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
        <FocusOnNavigate RouteData="@routeData" Selector="h1"/>
    </Found>
</Router>

Static discovery contains the "/test" definition while Router does not, which results in flickers if prerender is enabled. I believe to place all the pages in Client will help.

Describe the solution you'd like

I think Error page behavior is also related to this.

alternatives

  • Do not replace the DOM if nothing found in interactive Router, remain the static content for this scenario. This may be a bad idea, but it can make stuff like UseStatusCodePagesWithReExecute work.
  • Provide a centralized way to specify group of pages render as SSR with auto global enabled.

Will a nested <Router> help for the second, how?

If enhanced navigation is available for interactive client routing, navigation always goes through the interactive client-side router. This point is only relevant in an uncommon scenario where an interactive <Router> is nested inside a server-side rendered <Router> . In that case, the interactive router takes priority when handling navigation, so enhanced navigation isn't used for navigation because it's a server-side routing feature.Doc

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions