Skip to content

feat(Layout): add IsAutoNavigateWhenNotAuthorize parameter - #8503

Merged
ArgoZhang merged 6 commits into
mainfrom
feat-layout
Oct 9, 2026
Merged

ArgoZhang merged 6 commits into
mainfrom
feat-layout

Conversation

@ArgoZhang

@ArgoZhang ArgoZhang commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Link issues

fixes #8502

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Allow applications to disable automatic navigation when authorization fails while preserving the existing redirect behavior by default.

New Features:

  • Add a configurable option to control whether the layout automatically navigates unauthorized users to the login URL.

Tests:

  • Add unit coverage confirming unauthorized users remain on the current page when automatic navigation is disabled.

@sourcery-ai

sourcery-ai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds Layout.IsAutoNavigateWhenNotAuthorize, preserving the existing automatic redirect behavior by default while allowing consumers to disable unauthorized navigation; the location-change handler exits before authorization navigation logic when disabled.

Sequence diagram for configurable unauthorized navigation

sequenceDiagram
    participant Browser
    participant Layout
    participant Navigation
    participant Authorizing

    Browser->>Navigation: LocationChanged
    Navigation->>Layout: Navigation_LocationChanged
    alt IsAutoNavigateWhenNotAuthorize is false
        Layout-->>Navigation: return
    else IsAutoNavigateWhenNotAuthorize is true
        Layout->>Authorizing: OnAuthorizing
        Authorizing-->>Layout: authorization result
        Layout-->>Navigation: navigate to NotAuthorizeUrl when unauthorized
    end
Loading

File-Level Changes

Change Details Files
Add a configurable switch controlling automatic navigation for unauthorized users.
  • Introduce the IsAutoNavigateWhenNotAuthorize parameter with a default of true.
  • Short-circuit location-change authorization handling when automatic navigation is disabled.
  • Pass the NotAuthorized content without the null-forgiving operator.
src/BootstrapBlazor/Components/Layout/Layout.razor
src/BootstrapBlazor/Components/Layout/Layout.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#8502 Add a configurable Layout parameter controlling whether an unauthorized result automatically navigates to NotAuthorizeUrl, with the default behavior remaining enabled. ✅
#8502 When automatic navigation is disabled, continue invoking the authorization logic and displaying NotAuthorized while keeping the current URL unchanged. ❌ The new guard returns immediately from Navigation_LocationChanged when IsAutoNavigateWhenNotAuthorize is false. This skips the location-change authorization handling entirely, rather than only suppressing navigation to NotAuthorizeUrl, so the existing authorization check and NotAuthorized display may not occur for navigation events.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 9, 2026
@bb-auto bb-auto Bot added this to the v11.0.0 milestone Oct 9, 2026

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Oct 9, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor/Components/Layout/Layout.razor.cs" line_range="733" />
<code_context>
     private void Navigation_LocationChanged(object? sender, LocationChangedEventArgs e)
     {
+        // 如果未开启自动跳转未授权地址则不处理
+        if (!IsAutoNavigateWhenNotAuthorize)
+        {
+            return;
</code_context>
<issue_to_address>
**Protected routes render unchecked**

When `IsAutoNavigateWhenNotAuthorize` is false and a route relies on `OnAuthorizing` for authorization, `Navigation_LocationChanged` returns before invoking `OnAuthorizing` or updating `_authenticated`, so callback-based authorization is skipped and the layout can render protected content or keep showing `Main` instead of `NotAuthorized`.

Always run the authorization callback and update the authorization state; use `IsAutoNavigateWhenNotAuthorize` only to gate the redirect.

Also at `src/BootstrapBlazor/Components/Layout/Layout.razor.cs:734-736`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/BootstrapBlazor/Components/Layout/Layout.razor.cs:733


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/BootstrapBlazor/Components/Layout/Layout.razor.cs Outdated
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9905a87) to head (7e9f5e6).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8503   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          777       777           
  Lines        35159     35160    +1     
=========================================
+ Hits         35159     35160    +1     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@sourcery-ai
sourcery-ai Bot dismissed their stale review October 9, 2026 06:25

Sourcery withdrew this approval because the latest commits introduced blocking findings.

@bb-auto bb-auto Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto approved by bb-auto

@ArgoZhang
ArgoZhang merged commit 1eb200a into main Oct 9, 2026
6 checks passed
@ArgoZhang
ArgoZhang deleted the feat-layout branch October 9, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(Layout): add IsAutoNavigateWhenNotAuthorize parameter

1 participant