Angular 項目打包之后,部署到springboot項目中,刷新訪問404解決方法


解決方法1:

app.module.ts文件添加兩行代碼:

import { LocationStrategy, HashLocationStrategy } from '@angular/common';
    @NgModule({
     
        providers: [
     
        { provide: LocationStrategy, useClass: HashLocationStrategy },
     
        ]
     
    })

解決方法2:

在springboot項目application中添加

    @Component
    public class WebConfig implements ErrorPageRegistrar {


        @Override
        public void registerErrorPages(ErrorPageRegistry registry) {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/");
            registry.addErrorPages(error404Page);
        }


    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM