Springboot+Vue前端刷新404的解决方法

Springboot+Vue前端刷新404的解决方法,第1张

Springboot+Vue前端刷新404的解决方法

原因是因为没有定义404的页面,只需要在Springboot中加入如下代码即可

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 webServerFactoryCustomizer() {
        return factory -> {
            ErrorPage errorPage = new ErrorPage(HttpStatus.NOT_FOUND,"/index.html");
            factory.addErrorPages(errorPage);
        };
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4670826.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-07
下一篇2022-11-07

发表评论

登录后才能评论

评论列表(0条)

    保存