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);
};
}
}