Angular deployment - 404 on page Refresh

后端 未结 4 1218
小蘑菇
小蘑菇 2021-01-07 11:50

i would like to deploy my app in Angular to production server but I have problems. App works corectly when I use only angular routing (change component, not redirecting) but

4条回答
  •  天命终不由人
    2021-01-07 12:22

    If you are using angular 6,7 this method works (If you are okay with /#/ in your URL.

    In app.module.ts

    import {LocationStrategy, HashLocationStrategy} from '@angular/common';
    

    After import add following line to providers.

    {provide: LocationStrategy, useClass: HashLocationStrategy}
    

    ex:

    providers: [AuthService, 
                AuthGuard, 
                FlxUiDataTable,
                {provide: LocationStrategy, useClass: HashLocationStrategy}]
    

    This will solve your issue. Read Documentation here.

提交回复
热议问题