封装RouterView
大概逻辑:
先看一下路由的routes使用:
{
path:'xx',
component: xxx
}
path为跳转路径,并且对应一个要渲染的组件component
下面通过route.path 和当前路由的路径进行匹配,找到路由对应的组件,
并且渲染到页面
const comp = computed(() => {
const route = router.routes.find(
(route) => route.path === router.current.value
);
return route ? route.component : null;
});
完整代码
![](https://img2022.cnblogs.com/blog/962134/202203/962134-20220318230510706-1587282784.png)