angularjs – spring mvc捕获所有路线但只有未知路线
发布时间:2020-12-17 07:08:45 所属栏目:安全 来源:网络整理
导读:我有一个带有棱角的弹簧启动应用程序在前端. 我正在使用带有html5模式的ui-router,我希望spring能够在所有未知路由上呈现相同的index.html. // Works great,but it also overrides all the resources@RequestMappingpublic String index() { return "index";
我有一个带有棱角的弹簧启动应用程序在前端.
我正在使用带有html5模式的ui-router,我希望spring能够在所有未知路由上呈现相同的index.html. // Works great,but it also overrides all the resources @RequestMapping public String index() { return "index"; } // Seems do be the same as above,but still overrides the resources @RequestMapping("/**") public String index() { return "index"; } // Works well but not for subdirectories. since it doesn't map to those @RequestMapping("/*") public String index() { return "index"; } 所以我的问题是我如何创建一个回退映射但是可以通过资源? 解决方法
我发现最简单的方法是实现自定义404页面.
@Configuration public class MvcConfig { @Bean public EmbeddedServletContainerCustomizer notFoundCustomizer(){ return new NotFoundIndexTemplate(); } private static class NotFoundIndexTemplate implements EmbeddedServletContainerCustomizer { @Override public void customize(ConfigurableEmbeddedServletContainer container) { container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,"/")); } } } Neil McGuigan建议使用HandlerInterceptor,但我无法理解如何实现.我很高兴看到这将如何实现,因为使用html5历史推送状态的单页应用程序将需要此行为.我还没有真正找到解决这个问题的最佳方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |