Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular1 location html5mode equivalent in angular2

Tags:

angular

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: [
        proxyMiddleware,
        modRewrite([
          '^[^\\.]*$ /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?

like image 416
user3205675 Avatar asked Feb 06 '16 21:02

user3205675


1 Answers

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

NOTE

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.

like image 98
akp Avatar answered Oct 22 '22 21:10

akp