2

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

angular.module('myApp', ['ngRoute']).
  config(['$routeProvider','$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider.when('/', { templateUrl: 'views/home.html', controller: 'homeCtrl' });
    $routeProvider.when('/about', { templateUrl: 'views/about.html', controller: 'aboutCtrl' });

    $locationProvider.html5Mode(true);

}]);
1
  • Does not make a difference Commented Feb 23, 2014 at 20:31

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.