后台解决springboot+Vue项目整合后,刷新页面出现404,找不到页面的问题
解决方法:
在配置类中添加如下,将errorpage定向到index.html,代码如下
package com.ice.config;
/**
* @author 紫风
* @date 2021年10月11日 19:54
*/
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
//404错误页面重定向
@Configuration
public class ErrorConfigurar implements ErrorPageRegistrar {
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
ErrorPage[] errorPages = new ErrorPage[1];
errorPages[0] = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html");
// errorPages[1] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
// registry.addError(errorPages);
registry.addErrorPages(errorPages);
}
}