zoukankan      html  css  js  c++  java
  • angular当router使用userhash:false时路由404问题

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

    安装iis urlrewrite2.0组件

    在根目录下创建 Web.config

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="AngularJS Routes" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />   
              </conditions>
              <action type="Rewrite" url="/" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    .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(); 
    
  • 相关阅读:
    secFox setting
    Xmind settings lower
    Test435678
    Cmd管理员运行
    office install problems
    MSOCache office问题
    WeRun is mini-app
    解决谷歌跨域调试不可用
    xml文件读写
    c++ 矩阵运算库 Eigen等
  • 原文地址:https://www.cnblogs.com/francis67/p/10350018.html
Copyright © 2011-2022 走看看