1

I am building an AngularJS application, it works well with hash URL. If I click on an anchor <a href="#/3125/"> then the URL is updated to http://localhost:8000/app/index.html#/3125/ which is desired.

Now I plan to change the URL to HTML5 mode, so I configured the application with below code

var demoApp = angular.module('demoApp', ['demoResources']);
    demoApp.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode(true);
}]);

Unfortunately, this time if I click on the same anchor, I got URL escaped as http://localhost:8000/app/index.html#%2F3125%2F thus the link is broken. However, the expected URL is http://localhost:8000/app/index.html/3125.

Does anyone know why this is not working? I am using Angular 1.2.1

1 Answer 1

1

You should add a <base> tag in the <head> section of your application :

<base href="/app"/>

See the "Relative Links" section in the $location documentation.

See also AngularJS subdirectory routing not working, with <base> tag applied

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

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.