Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

How can a Blazor server side app redirect from http://hostname to http://hostname/route1 on load?

For several of the sites I have built using MVC/TypeScript or MVC/Angular I have needed to redirect the user immediately from http://hostname to http://hostname/route1. I am trying to figure out how to implement the same functionality with Blazor Server Side.

I am aware that this can be done using the IIS URL Rewrite engine, however, it has not been determined if the application will be hosted under IIS, self-hosted on Windows, or hosted on Linux.

Is this possible? If so, what is the best practice approach for this implementation?

Thanks

question from:https://stackoverflow.com/questions/65926582/how-can-a-blazor-server-side-app-redirect-from-http-hostname-to-http-hostnam

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do a redirect on OnInitialize on your root page (maybe index.razor )

@page "/"
@inject NavigationManager MyNavigationManager
@code
{
    protected override void OnInitialized()
    {
        MyNavigationManager.NavigateTo("route1");
    }
}

Learn more about navigationManager at NavigationManager cheatsheet


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...