How to route in angular 4

前端 未结 3 901
情话喂你
情话喂你 2021-02-14 12:14

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

3条回答
  •  粉色の甜心
    2021-02-14 12:22

    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.

提交回复
热议问题