封裝RouterView
大概邏輯:
先看一下路由的routes使用:
{
path:'xx',
component: xxx
}
path為跳轉(zhuǎn)路徑,并且對(duì)應(yīng)一個(gè)要渲染的組件component
下面通過route.path 和當(dāng)前路由的路徑進(jìn)行匹配,找到路由對(duì)應(yīng)的組件,
并且渲染到頁(yè)面
const comp = computed(() => {
const route = router.routes.find(
(route) => route.path === router.current.value
);
return route ? route.component : null;
});
完整代碼


浙公網(wǎng)安備 33010602011771號(hào)