需求是项目A要使用iframe内嵌项目B的页面,
由于需要嵌套的页面很多,每个页面路径和参数又各不相同,
所以我们在项目B里做了一个中转页面,这样就能自己掌控项目A传递过来的东西了;
routes.js
增加一个菜单:
{
path: '/redirect/:path*', // /redirect/:path* 表示这个路由会匹配以 /redirect/ 开头的所有路径,其中:path* 是一个动态参数,可以匹配任意后续路径部分。
component: () =>
import('@/components/base/redirect')
},
redirect.vue
<script>
export default {
name: 'Redirect',
created() {
const {
params: { path },
query
} = this.$route
this.$router.replace({ path: '/' + path, query })
},
render(h) {
return h()
}
}
</script>
App.vue
mounted() {
// 监听到需要跳转到内嵌的页面就跳到重定向页面
const { fullPath } = this.$route
this.$router.replace({ path: '/redirect' + fullPath })
}