question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor: More flexible Router / layout display

See original GitHub issue

Currently, we have a hardcoded set of assumptions about what you want to do with a router, i.e.,

  • You want to display the page inside its layouts
  • You want to authorize access to the page, but still show its layouts regardless

The logic for this is all internal to Router and LayoutDisplay (being renamed to PageDisplay). Instead of this, we could reduce Router to be a templated component that just finds a page and parameters for you. Then you could choose how to render that, and where authorization wrappers go, etc., yourself.

Example:

<Router AppAssembly="@typeof(App).Assembly" Context="routeContext">
    <NotFoundContent>
        <LayoutDisplay Layout="@typeof(MainLayout)">
            <h1>Not found</h1>
            Sorry, there's nothing here.
        </LayoutDisplay>
    </NotFoundContent>
    <FoundContent>
        <AttributeAuthorizeView Page="@routeContext.Page">
            <Authorized>
                <LayoutDisplay Page="@routeContext.Page" PageParameters="@routeContext.Parameters" />            
            </Authorized>
            <NotAuthorized>
                <LayoutDisplay Layout="@typeof(MainLayout)">
                    <h1>Access denied</h1>
                    Go away.
                </LayoutDisplay>
            </NotAuthorized>
            <Authorizing>
                <LayoutDisplay Layout="@typeof(MainLayout)">
                    <h1>Please wait</h1>
                    Checking authorization...
                </LayoutDisplay>
            </Authorizing>
        </AttributeAuthorizeView>
    </FoundContent>
</Router>

This would completely nuke issue #10445 in the most comprehensive manner.

One drawback is the amount of repetition of specifying <LayoutDisplay Layout="@typeof(MainLayout)"> here, but doing this does eliminate any need for a DefaultLayout concept, and completely decouples Router, AuthorizeView, and LayoutDisplay from each other. They would no longer need to have any awareness of each others’ existence.

@rynowak @danroth27 @javiercn What’s your gut response to this? Does it look too complicated, or do you think the flexibility warrants all the explicit code?

Plan

  • Implement LayoutView
  • Implement RouteView
  • Update Router to new factoring
  • Implement AuthorizeRouteView
  • Remove CascadingAuthenticationState No, keeping it.
  • Remove PageDisplay
  • Update E2E tests
  • Update project templates

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
rynowakcommented, Jul 25, 2019

Reactivating this based on API review discussions. This solve a bunch of hard layering problems that we think are worth taking on. We can think of a few practical design issues in this area that will help users as well, and decoupling all of these things is a good long term choice.

We’re planning to move the authorization features to Microsoft.AspNetCore.Components.Authorization

We’re planning to move the forms support to Microsoft.AspNetCore.Components.Forms.

We plan to drop Microsoft.JSInterop as a dependency from M.A.Components and it will no longer have any dependencies 👍

0reactions
SteveSandersonMScommented, Aug 5, 2019

Done in #12800

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor layouts
A Blazor layout is a Razor component that shares markup with components that reference it. Layouts can use data binding, dependency injection, ...
Read more >
Adding Dynamic Routing, Layouts and RouteViews to the ...
This article shows how to add Dynamic Routing, Layouts and RouteViews to the Blazor App Component. Overview. App is the Blazor UI root...
Read more >
Adding Dynamic Routing, Layouts and RouteViews to the ...
This article shows how to add Dynamic Routing, Layouts and RouteViews to the Blazor App Component. App is the Root Component in the...
Read more >
Building a Custom Router for Blazor
In this post, I'm going to show you how you can build your own convention based router component to replace the default router...
Read more >
Use pages, routing, and layouts to improve Blazor navigation
We continue learning how to build interactive web apps with C# and Blazor LIVE! Today,we are going to learn how to manage request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found