前端vue,打包整合進後端springboot的resources裏面後,運行只要刷新就報404

vue打包後,其實就剩index.html和一堆靜態資源,頁面的加載和替換都是通過刷新index.html種的dom來實現的(應該是這樣,可能表述不是很好),所以做個重定向就可以了。(博主是這麼解決的,網上還有很多人是各種路徑錯誤,大家可以嘗試下自己是哪個原因)

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class ServletConfig {
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        return factory -> {
            ErrorPage errorPage = new ErrorPage(HttpStatus.NOT_FOUND,"/index.html");
            factory.addErrorPages(errorPage);
        };
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章