Angular1 location html5mode equivalent in angular2

I am trying to find where I can enable html5mode in angular2. Unfortunately, it was not possible to find it from the documentation or anywhere. I use gulp and browser sync to download my files. I have seen many say use connect-modrewrite something like

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

I installed it, but it still doesn't work, and I get 404 for anything other than the main URL. Any clues about this?

+5
source share
1 answer

What you are looking for is PathLocationStrategy , which is LocationStrategy by default

Note

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

Also remember to set the <base path="/" /> to the beginning of the HTML code.

+5
source

Source: https://habr.com/ru/post/1242454/


All Articles