AngularJS: html5Mode(true) causing 404 error

前端 未结 2 587
孤街浪徒
孤街浪徒 2021-01-23 04:03

I am trying to remove # tag on my app using $locationProvider.html5Mode(true). It takes out the # but now I get 404 errors

相关标签:
2条回答
  • 2021-01-23 04:47

    It turns out if one is usung $locationProvider.html5Mode(true). You have to set a base url (<base href="/appFolder/" />)... according to this answer

    0 讨论(0)
  • 2021-01-23 05:02

    For .net Project you'll need to also need to add rewrite rule in web config. Add below code to web.config & in head of single page section add href is of path of your single page

    <system.webServer>    <rewrite>
    <rules>
      <rule name="RewriteRules" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
        </conditions>
        <action type="Rewrite" url="/index.html" />
      </rule>
    </rules>  </rewrite></system.webServer>
    
    0 讨论(0)
提交回复
热议问题