在vue3中,当父路由和子路由不同时存在场景下的一些问题 #6076
Unanswered
wangrongding
asked this question in
Help/Questions
Replies: 2 comments 4 replies
-
如果只是为了达到 List 和 Detail 同时只有一个存在. 为什么要这样 |
Beta Was this translation helpful? Give feedback.
1 reply
-
This can work in Vue3. import { createRouter, createWebHistory } from "vue-router";
import List from "./components/List";
import Detail from "./components/Detail";
const routes = [
{
path: "/list",
name: "list",
component: List
},
{
path: "/list/detail/:id",
component: Detail,
name: "detail"
}
];
export const router = createRouter({
history: createWebHistory(),
routes
});
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
场景:
假设有一个List列表页面,点击List列表页面中的项目,跳转到Detail详情页。
( xxxxx/list --> xxxxx/list/detail?id=123 )
在大多数情况下我们普遍的期望是当进入
Detail详情页
路由时,页面中只显示相应的Detail
组件,而不再显示List
页面的内容。问题:
如果只是为了达到 List 和 Detail 同时只有一个存在.
可以将路由重新设计为扁平化的。然而这会破坏这两个路由本身所拥有的父子语义,因为 UI 的表现而去破坏语义是不理想的。其次,我们项目中还有一个根据路由层级自动生成的面包屑导航,破坏 list 和 detail 的父子关系会导致面包屑导航无法正确工作。
或者是像这样
问题源自于:https://liximomo.github.io/vue-router-replace
具体演示可以看这个示例 👉 链接
想问一下在 Vue3 中,如何像三个方法一样实现呢?或者还有其他更好的方法?
Beta Was this translation helpful? Give feedback.
All reactions