Angular 2 Routing Does Not Work When Deployed to Http Server

前端 未结 18 1904
误落风尘
误落风尘 2020-12-07 22:42

I am going to develop a simple Angular 2 application. I have created a project with routing, using Angular CLI and added several components to the app using \'ng generate co

18条回答
  •  执笔经年
    2020-12-07 23:11

    You can do it while registering your RouterModule.forRoot, you can pass a second object with propert {useHash: true} like the below :

    import {NgModule} from '@angular/core';
    import {BrowserModule} from '@angular/platform-browser';
    import {AppComponent} from './app.component';
    import {appRoutes} from './app.routes';
    
    @NgModule({
       declarations: [AppComponent],
       imports: [BrowserModule],
       RouterModule.forRoot(appRoutes , {useHash: true})],
       providers: [],
       bootstrap: [AppComponent],
    })
    export class AppModule {}
    

提交回复
热议问题