【发布时间】:2019-05-28 07:06:43
【问题描述】:
我在页面加载时添加动态子组件。在父级的 OnCreated 中添加子路由不会使页面在我们刷新页面时正常工作。
因此,我正在解析页面模板(当页面加载时我知道它们)。
我现在正在寻找一种方法来了解与 href 匹配的路线。 Vue-js 使用 path-to-regexp,我的问题很简单。
我想知道匹配的组件
const router = new VueRouter({
routes: [
// dynamic segments start with a colon
{ path: '/user/:id', component: User },
{ path: '/foo/bar', component: FooBar },
]
})
// Reverse of this
var matchingComponent = howDoIDothis(/foo/bar) // this should give me the matching
我需要这个,以便我可以从路径中删除,然后将子组件动态添加到父组件。
【问题讨论】:
标签: vue.js vue-router vue-directives vuejs-transition