Skip to content

Blazor: Let browser handle hash change #52583

Closed
@davhdavh

Description

@davhdavh

Background and Motivation

As I can see there are 3 cases with hash:
a. Navigate to a hash on a different page. That was addressed in #8393
b. Blazor uses hash for page navigation. That is #6175 .
c. Navigate to a hash on the current page.

This request is to address the latter.

As I can see there are 3 behaviors that a developer might want:

  1. Let the browser deal with it.
  2. DOM event listener for popstate or hashchange and handle navigation event via javascript.
  3. SSR (current)

The current behavior for blazor.web.js is pretty broken IMHO: Blazor makes a full intercept and a full SSR and then uses the feature from #8393 to navigate to the element.

From the point of view of Blazor 1 and 2 are identical in the fact that if Blazor does nothing, that is the default browser behavior.

Proposed API

Add ignoreHashNavigationOnSamePage to SsrStartOptions.

Alternatively, respect <meta name="ignoreHashNavigationOnSamePage" /> (or something similar), so the individual page can handle it through <HeadContent>.

Alternatively, my preferred behavior: make it the default (It makes no sense to do a SSR on same-page hash change).

Risks

There might be someone somewhere that actually reads url hash server-side.

Metadata

Metadata

Assignees

Labels

api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions