angular当router使用userhash:false时路由404问题

angular当router使用userhash:false时路由404问题

安装iis urlrewrite2.0组件

在根目录下创建 Web.config


<system.webServer>












</system.webServer>

.netcore 中间件方法

app.Use(async (context, next) =>  
{  
    await next();  
    if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))  
    {  
        context.Request.Path = "/index.html";  
        context.Response.StatusCode = 200;  
        await next();  
    }  
});  

纯angular项目可以移除其它的默认首页

DefaultFilesOptions options = new DefaultFilesOptions();  
options.DefaultFileNames.Clear();  
options.DefaultFileNames.Add("/index.html");  
app.UseDefaultFiles(options);  
app.UseStaticFiles(); 
posted @ 2019-02-03 11:52  TT.Net  阅读(526)  评论(0)    收藏  举报