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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With