mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(vue): correctly render child pages in tabs (#22141)
This commit is contained in:
@ -6,6 +6,14 @@ import { RouteInfo,
|
|||||||
|
|
||||||
export const createViewStacks = () => {
|
export const createViewStacks = () => {
|
||||||
let viewStacks: ViewStacks = {};
|
let viewStacks: ViewStacks = {};
|
||||||
|
const tabsPrefixes = new Set();
|
||||||
|
|
||||||
|
const addTabsPrefix = (prefix: string) => tabsPrefixes.add(prefix);
|
||||||
|
const hasTabsPrefix = (path: string) => {
|
||||||
|
const values = Array.from(tabsPrefixes.values());
|
||||||
|
const hasPrefix = values.find((v: string) => path.includes(v));
|
||||||
|
return hasPrefix !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const getViewStack = (outletId: number) => {
|
const getViewStack = (outletId: number) => {
|
||||||
return viewStacks[outletId];
|
return viewStacks[outletId];
|
||||||
@ -92,6 +100,8 @@ export const createViewStacks = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
addTabsPrefix,
|
||||||
|
hasTabsPrefix,
|
||||||
findViewItemByRouteInfo,
|
findViewItemByRouteInfo,
|
||||||
findLeavingViewItemByRouteInfo,
|
findLeavingViewItemByRouteInfo,
|
||||||
createViewItem,
|
createViewItem,
|
||||||
|
@ -16,13 +16,27 @@ import { fireLifecycle, generateId, LIFECYCLE_DID_ENTER, LIFECYCLE_DID_LEAVE, LI
|
|||||||
let viewDepthKey: InjectionKey<0> = Symbol(0);
|
let viewDepthKey: InjectionKey<0> = Symbol(0);
|
||||||
export const IonRouterOutlet = defineComponent({
|
export const IonRouterOutlet = defineComponent({
|
||||||
name: 'IonRouterOutlet',
|
name: 'IonRouterOutlet',
|
||||||
setup() {
|
setup(_, { attrs }) {
|
||||||
const vueRouter = useRouter();
|
const vueRouter = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const depth = inject(viewDepthKey, 0);
|
const depth = inject(viewDepthKey, 0);
|
||||||
|
|
||||||
// TODO types
|
// TODO types
|
||||||
const matchedRouteRef: any = computed(() => route.matched[depth]);
|
let tabsPrefix: string | undefined;
|
||||||
|
const matchedRouteRef: any = computed(() => {
|
||||||
|
const matchedRoute = route.matched[depth];
|
||||||
|
|
||||||
|
if (attrs.tabs && !tabsPrefix) {
|
||||||
|
tabsPrefix = route.matched[0].path;
|
||||||
|
viewStacks.addTabsPrefix(tabsPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchedRoute && attrs.tabs && route.matched[depth + 1]) {
|
||||||
|
return route.matched[route.matched.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedRoute;
|
||||||
|
});
|
||||||
|
|
||||||
provide(viewDepthKey, depth + 1)
|
provide(viewDepthKey, depth + 1)
|
||||||
|
|
||||||
@ -205,6 +219,10 @@ export const IonRouterOutlet = defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentRoute = ionRouter.getCurrentRouteInfo();
|
const currentRoute = ionRouter.getCurrentRouteInfo();
|
||||||
|
const hasTabsPrefix = viewStacks.hasTabsPrefix(currentRoute.pathname)
|
||||||
|
const isLastPathTabs = viewStacks.hasTabsPrefix(currentRoute.lastPathname);
|
||||||
|
if (hasTabsPrefix && isLastPathTabs && !attrs.tabs) { return; }
|
||||||
|
|
||||||
let enteringViewItem = viewStacks.findViewItemByRouteInfo(currentRoute, id);
|
let enteringViewItem = viewStacks.findViewItemByRouteInfo(currentRoute, id);
|
||||||
|
|
||||||
if (!enteringViewItem) {
|
if (!enteringViewItem) {
|
||||||
|
Reference in New Issue
Block a user