Redirect unknown requests to index.html in springboot

北战南征 提交于 2019-11-29 17:08:54

As a work-a-round I've added the Angular Routes in a RequestMapping annotation and pointed them all at the index.html:

@RequestMapping({"/login", "/logout"})
public String index() { return "index.html"; }

Edit: As a better work-a-round, you can make the controller implement ErrorController, override the getErrorPath method, then add a mapping for /error which will act as a catch-all (or mapping missing) method.

@Controller
public class TheOneController implements ErrorController {

    @RequestMapping("/error")
    public String index() {
        return "index.html";
    }

    @Override
    public String getErrorPath() {
        return "index.html";
    }
}

Now the index method will handle anything that can't be found and render the index.html.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!