Home Ask Login Register

Developers Planet

Your answer is one click away!

user3205675 February 2016

Angular1 location html5mode equivalent in angular2

I am trying to find where I can enable html5mode in angular2. Unfortunately couldnt find it out from the documentation or anywhere. I am using gulp and browser-sync to load my files. I have seen that many says to use connect-modrewrite something like

browserSync.instance = browserSync.init({
    server: {
      baseDir: ['app'],
      middleware: [
          '^[^\\.]*$ /index.html [L]'

I set it but still it doesnt work and I get 404 for anything but the main url. Any clues on this?


akp February 2016

What you are looking for is the PathLocationStrategy which is the default LocationStrategy


When using this you will need to set your server to redirect ALL requests to the root URL. For example if your user requests myApp.com/someRoute then assets will be resolved from that url which is incorrect. Instead you want the server to serve the index.html page regardless of the route specified, but still keep the route intact so that it can be used by the client-side application.

Also be sure to set your <base path="/" /> tag in the head of your HTML.

Post Status

Asked in February 2016
Viewed 2,111 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life