Remove # from URL in angular js SPA

帅比萌擦擦* 提交于 2019-12-25 08:38:00

问题


I have done, a lot of research on this, I will try my best to explain the detail code bit wise,

I am creating an application using angular js with web api as service, when i run the application i get the # in URL. In order to remove the # from the URL, we need to add the below like in angular config, almost all suggested to add,

$locationProvider.html5Mode(true);

so i have added like this,

angular.module('myapp', ['ui.router'])
  .config([......., '$locationProvider', 
    function (......., $locationProvider) {
        $locationProvider.html5Mode(true);
        .........
}]);

then i have also added the base tag inside the tag in index(master) file, as shown below,

<base href="/" />

When i was did this much, i get HTTP Error 404.0 - Not Found when i reload/refresh the page, then i did little more R&D, and i have found someone had suggested to add the below code in web.config,

<system.webServer>
    <rewrite>
     <rules> 
      <rule name="Main Rule" 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>

When i add this i get error when i try to login, i get 405 error as shown below,

But when i remove the code added in web.config then it works fine, but again when i reload i get 404 error.

Is there something to do in web api config, i did some stuff there to but no result, anyone can please help me.

Please do let me know if you need any other details,

Thanks in adv..

来源:https://stackoverflow.com/questions/41788560/remove-from-url-in-angular-js-spa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!