How to handle angular2 route path in Nodejs?

前端 未结 3 1141
粉色の甜心
粉色の甜心 2020-12-06 05:22

I am working on a NodeJS app with Angular2. In my app, I have a home page and search page. For home page I have an HTML page that will render for the localhost:3000/

3条回答
  •  余生分开走
    2020-12-06 05:44

    You need to use HashLocationStrategy

    import { LocationStrategy, HashLocationStrategy } from "angular2/router";
    bootstrap(AppComponent, [
     ROUTER_PROVIDERS,
     provide(LocationStrategy, { useClass: HashLocationStrategy })
    ]);
    

    In your bootstrap file.

    If you want to go with PathLocationStrategy ( without # ) you must setup rewrite strategy for your server.

提交回复
热议问题