[英]Html5 routing with Spring and Angular
I'm trying to implement HTML5 routing with Spring-boot and Angular 1.5, following this article . 我正在尝试使用Spring-boot和Angular 1.5实现HTML5路由,遵循本文 。
At some point I need to redirect all the angular routes to the base path with a controller like this: 在某些时候,我需要使用这样的控制器将所有角度路径重定向到基本路径:
@Controller
public class UrlController {
// Match everything without a suffix (so not a static resource)
@RequestMapping(value = "/{path:[^\\.]*}"))
public String redirect(HttpServletRequest request) {
// Forward to home page so that route is preserved.
return "forward:/";
}
}
While the regular expression matches most of the URLS, like dashboard, search etc: 正则表达式匹配大多数URL,如仪表板,搜索等:
2016-08-05 16:39:58 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:306 - Looking up handler method for path /dashboard
2016-08-05 16:39:58 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:313 - Returning handler method UrlController.redirect(javax.servlet.http.HttpServletRequest,java.lang.String)]
2016-08-05 16:39:58 DEBUG o.s.b.f.s.DefaultListableBeanFactory:251 - Returning cached instance of singleton bean 'urlController'
2016-08-05 16:39:58 DEBUG o.s.w.s.DispatcherServlet:947 - Last-Modified value for [/dashboard] is: -1
2016-08-05 16:39:58 DEBUG c.a.a.w.i.LoggingInterceptor:22 - Start processing url request: https://localhost:8443/dashboard
redirecting to home page from url https://localhost:8443/dashboard
2016-08-05 16:39:58 DEBUG c.a.a.w.i.LoggingInterceptor:35 - Finished processing url request: https://localhost:8443/dashboard, duration: 0[ms]
Others are ignored and not matched at all, like https://localhost:8443/faults/64539352 其他人被忽略,根本不匹配,例如https:// localhost:8443 / faults / 64539352
2016-08-05 17:00:05 DEBUG o.s.w.s.DispatcherServlet:861 - DispatcherServlet with name 'dispatcherServlet' processing GET request for [/faults/64539352]
2016-08-05 17:00:05 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:306 - Looking up handler method for path /faults/64539352
2016-08-05 17:00:05 DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping:316 - Did not find handler method for [/faults/64539352]
The regular expression seems to be fine if you test it in regexplanet , but it does not match what I want if I put it in the @RequestMapping. 如果你在regexplanet中测试它,正则表达式似乎没问题 ,但是如果我把它放在@RequestMapping中,它就不符合我想要的。 Does anybody know how to make it work, or even better how to do it without regular expressions?
有没有人知道如何使它工作,甚至更好的方法如何没有正则表达式?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.