解决第二个问题的方式是对vue的路由的路径做rewrite,交给router来处理,而不是springboot自己处理,rewrite时可以考虑路由的路径统一增加后最,然后在springboot中编写过滤拦截特定后缀来做请求转发交给vue的路由处理。如:
const router = new VueRouter({
mode: ‘history’,
base: __dirname,
routes: [
{
path: ‘/ui/first.vhtml’,
component: First
},
{
path: ‘/ui/second.vhtml’,
component: secondcomponent
}
]
})
后端拦截到带有vhtml的都交给router来处理,这种方式在后端写过滤器拦截后打包是完全可行的,但是前端开发的直接访问带后缀的路径会有问题。
另外一种方式是给前端的路由path统一加个前缀比如/ui,这时后端写过滤器匹配该前缀,也不会影响前端单独开发是的路由解析问题。过滤器参考如下:
/**
-
be used to rewrite vue router
-
@author yu on 2017-11-22 19:47:23.
*/
public class RewriteFilter implements Filter {
/**
- 需要rewrite到的目的地址
*/
public static final String REWRITE_TO &#