本文主要是介绍前端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 {@Beanpublic WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {return factory -> {ErrorPage errorPage = new ErrorPage(HttpStatus.NOT_FOUND,"/index.html");factory.addErrorPages(errorPage);};}
}
这篇关于前端vue,打包整合进后端springboot的resources里面后,运行只要刷新就报404的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!