Route to a particular page based on a Cascading Value. (Similar to how AuthorizeRouteView works)
Jeremy Champion
0
Reputation points
In the following code example, I am using the AuthorizeRouteView to send users to the LoginRedirect page if they are not authenticated.
If they are authenticated, I would then like to route them based on a value in my CascadingAppState.
I've tried writing a custom route view (which failed) and I've tried hooking the NavigationManager LocationChanged event and checking to see if I need to redirect there.
Neither worked (at least with my implementation).
Any help would be much appreciated!
<CascadingAuthenticationState>
<CascadingAppState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<LoginRedirect />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAppState>
</CascadingAuthenticationState>
Sign in to answer