diff --git a/BREAKING.md b/BREAKING.md index 187e15f13c..2840971444 100644 --- a/BREAKING.md +++ b/BREAKING.md @@ -27,6 +27,7 @@ This is a comprehensive list of the breaking changes introduced in the major ver * [Config Provider](#config-provider) - [Vue](#vue) * [Tabs Config](#tabs-config) + * [Tabs Router Outlet](#tabs-router-outlet) * [Overlay Events](#overlay-events) - [Browser and Platform Support](#browser-and-platform-support) @@ -220,6 +221,47 @@ const routes: Array = [ In the example above `tabs/tab1/view` has been rewritten has a sibling route to `tabs/tab1`. The `path` field now includes the `tab1` prefix. +#### Tabs Router Outlet + +Developers must now provide an `ion-router-outlet` inside of `ion-tabs`. Previously one was generated automatically, but this made it difficult for developers to access the properties on the generated `ion-router-outlet`. + +**Old** +```html + + + ... + + + + +``` + +**New** +```html + + + + ... + + + + +``` + #### Overlay Events Overlay events `onWillPresent`, `onDidPresent`, `onWillDismiss`, and `onDidDismiss` have been removed in favor of `willPresent`, `didPresent`, `willDismiss`, and `didDismiss`. diff --git a/packages/vue/src/components/IonTabs.ts b/packages/vue/src/components/IonTabs.ts index d519cc02ff..32221c3be9 100644 --- a/packages/vue/src/components/IonTabs.ts +++ b/packages/vue/src/components/IonTabs.ts @@ -1,5 +1,4 @@ import { h, defineComponent, VNode } from 'vue'; -import { IonRouterOutlet } from './IonRouterOutlet'; const WILL_CHANGE = 'ionTabsWillChange'; const DID_CHANGE = 'ionTabsDidChange'; @@ -7,20 +6,21 @@ const DID_CHANGE = 'ionTabsDidChange'; export const IonTabs = /*@__PURE__*/ defineComponent({ name: 'IonTabs', emits: [WILL_CHANGE, DID_CHANGE], - data() { - return { didWarn: false } - }, render() { - const { $slots: slots, $emit, $data } = this; + const { $slots: slots, $emit } = this; const slottedContent = slots.default && slots.default(); - let userProvidedRouterOutlet; + let routerOutlet; + /** + * Developers must pass an ion-router-outlet + * inside of ion-tabs. + */ if (slottedContent && slottedContent.length > 0) { - /** - * If developer passed in their own ion-router-outlet - * instance, then we should not init a default one - */ - userProvidedRouterOutlet = slottedContent.find((child: VNode) => child.type && (child.type as any).name === 'IonRouterOutlet'); + routerOutlet = slottedContent.find((child: VNode) => child.type && (child.type as any).name === 'IonRouterOutlet'); + } + + if (!routerOutlet) { + throw new Error('IonTabs must contain an IonRouterOutlet. See https://ionicframework.com/docs/vue/navigation#working-with-tabs for more information.'); } let childrenToRender = [ @@ -31,42 +31,15 @@ export const IonTabs = /*@__PURE__*/ defineComponent({ 'flex': '1', 'contain': 'layout size style' } - }, (userProvidedRouterOutlet) ? userProvidedRouterOutlet : [h(IonRouterOutlet)]) + }, routerOutlet) ]; - if (userProvidedRouterOutlet && !$data.didWarn) { - console.warn(`[@ionic/vue Deprecation] Starting in Ionic Vue v6.0, developers must add an 'ion-router-outlet' instance inside of 'ion-tabs'. - - Before: - - - - ... - - - - After: - - - - - ... - - - - Be sure to import 'IonRouterOutlet' from '@ionic/vue' and provide that import to your Vue component. See https://ionicframework.com/docs/vue/navigation#working-with-tabs for more information. - `); - - $data.didWarn = true; - } - /** * If ion-tab-bar has slot="top" it needs to be * rendered before `.tabs-inner` otherwise it will * not show above the tab content. */ if (slottedContent && slottedContent.length > 0) { - /** * Render all content except for router outlet * since that needs to be inside of `.tabs-inner`. diff --git a/packages/vue/test-app/src/views/Tabs.vue b/packages/vue/test-app/src/views/Tabs.vue index 3c371b8230..be7329a014 100644 --- a/packages/vue/test-app/src/views/Tabs.vue +++ b/packages/vue/test-app/src/views/Tabs.vue @@ -2,6 +2,7 @@ + diff --git a/packages/vue/test-app/src/views/TabsSecondary.vue b/packages/vue/test-app/src/views/TabsSecondary.vue index 2319da4234..99e8b53187 100644 --- a/packages/vue/test-app/src/views/TabsSecondary.vue +++ b/packages/vue/test-app/src/views/TabsSecondary.vue @@ -2,6 +2,7 @@ + @@ -24,12 +25,12 @@