I have an angular 4 project and when I run it from localhost:4200/route-a
, it works fine and when I refresh the browser, all works well as expected. However, when I
Sometimes there could be that you don't have access to the server configuration. There is another possible solution to this.
In the import
of the RouterModule
where there is something like:
RouterModule.forRoot( routes )
You can add the useHash
this way:
RouterModule.forRoot( routes, { useHash: true } )
then rebuild your project with the production flag and the URLs now will be like:
http://yourserver/#/page1/
this way, thanks to the hash, the app will work without any problems and the only thing needed is setting the useHash
on the RouterModule and rebuilding your app.
The rewrite rules are good but I think it is good having more options.