-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different routers for each tab #103
Comments
Since they just made the fix so you can add a custom event to handle tab buttons (not yet published to npm), you can do this manually, assuming named views still work with Vue Router Named Views:
Router config
|
@mattsteve the problem with this is that the history is shared between the two tabs—it is not possible to get away with only one router. Changing the page on the first tab will change the page on the second, which is certainly not what you want. I ended up figuring out that you can still do what I did, and nest routers. However, I ended up switching to Ionic's |
@lights0123 thanks for sharing your implementation, sorry for not replying earlier. Could you share your implementation using |
@michaeltintiuc Here's the complete project. I actually removed all Ionic-Vue parts, and I'm now just using Ionic components directly from Vue because I got a bunch of errors when migrating to Ionic 5. This commit is the last commit to use this repository, on Ionic 4. Here's the main layout of my app before I switched to using my own bindings: One central component for the main app:<template>
<ion-app>
<ion-tabs>
<ion-tab tab="news">
<ion-nav root="app-news" />
</ion-tab>
<ion-tab tab="saved">
<ion-nav root="app-saved" />
</ion-tab>
<ion-tab tab="settings">
<ion-nav root="app-settings" />
</ion-tab>
<ion-tab-bar slot="bottom" ref="tabBar">
<ion-tab-button tab="news" @click="click('news')">
<ion-icon name="paper" />
<ion-label>News</ion-label>
</ion-tab-button>
<ion-tab-button tab="saved" @click="click('saved')">
<ion-icon :src="bookmarkURL" class="bookmark-icon" />
<ion-label>Saved</ion-label>
</ion-tab-button>
<ion-tab-button tab="settings" @click="click('settings')">
<ion-icon name="settings" />
<ion-label>Settings</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-app>
</template> A router:/* Note: I'm implicitly letting there be more than this route, as they are automatically pushed by <ion-tabs>, and Ionic takes care of displaying different components */
/* This is the only Vue router in the entire project, everything else is done through Ionic APIs */
/* This was removed in my latest version, where I switch away from using this repo */
router: new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes: [{ path: '/', redirect: '/news' }],
}), Each page has:<template>
<!-- <fragment> seems to be needed when using this as a component, placing the header and content in a <div> broke stuff -->
<!-- Vue 3 is getting multi-component roots (I think, right?) -->
<fragment>
<ion-header>
<ion-toolbar>
<ion-title><logo /></ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
whatever
</ion-content>
</fragment>
</template>
<script lang="ts">
/* Hack to make each component be a child of the main Vue instance so things like Vuex
* are available from each component, and makes debugging via the Vue Devtools plugin
* possible
*
* Very clunky, I'd like to get rid of it but it works 🥴 (except hot-reload breaks half the time,
* but stable in production)
*/
export const injectParent = {
beforeCreateVueInstance(RootComponentDefinition) {
RootComponentDefinition.parent = window.vue;
RootComponentDefinition.store = window.vue.$store;
return RootComponentDefinition;
},
};
/* I'm using vue-class-component, and `News` is the name of my default export
* This will likely be different (namely not including `.options`) if you're using the standard
* `export default`, and I have no clue what you would do with the new Composition API
*
* Note how this matches up with the `root` attribute of each <ion-nav />
*/
Vue.customElement('app-news', (News as any).options, injectParent);
</script> Once, to initialize that:import Vue from 'vue';
import vueCustomElement from 'vue-custom-element';
import { Plugin } from 'vue-fragment';
import Vue from 'vue';
Vue.use(vueCustomElement); This setup has a few advantages:
I understand that you probably don't want to make everyone follow these same steps, which is why I've basically migrated away from this repo (as it was getting in the way with in Ionic 5). However, the lack of native iOS feel and this issue was a dealbreaker for me. |
Thanks for the example and feedback @lights0123 I think most of this stuff makes a lot of sense and is the general direction v3 is going in. Would be interested in hearing your thoughts on the new version when it's out of alpha |
You can give a try with the vue 3 version, |
I'm trying to test out the tabs functionality with Vue 3 and ionic-vue@next, and I'm stuck.
I've made a setup like its described in the https://ionicframework.com/docs/api/tabs , just adapted to ionic-vue components, and I keep getting these errors. Can you give me some working example or point me at some direction or resource so I can figure it out? 🙏 Thanks |
Sure, here's my setup with a router:
Each component rendered by the router is similar to this:
In this example each tab has sub-routes for navigation, meaning that in order to resolve IonRouterView we'd be using the router's nested routes defined by the
Note that we're using |
Thanks a lot. You've pointed me in the right direction with the multiple nested children routes. To be honest it seems a little odd that you have 2 levels of children routes required to have tabbed routing, but I guess it makes sense because root tab routes should not have animation. I have one more issue, and I think it's related to tabs. ios swipe back gesture doesn't work, it just freezes, and the tab bar disappears. It's strange that I'm not seeing any console error. I've pushed the code here so you can reproduce and give me a hand if you can |
@meoweloper Please see this PR against your repo https://github.com/meoweloper/ionic-vue-3/pull/1 |
See version |
Glad to hear that separate history is in the works, I think thats the missing piece that will push tabs to a beta state. |
I found that same issue component type, just didn't know how to fix it 👶 ⌨️ |
Are you saying you get the same error? |
No, you fixed it in alpha.14. Just saying I failed to fix it myself. |
It was a library issue that I introduced some time ago, it's on me :) |
I'm writing a mobile app. Each tab should have its own navigation stack, i.e. you can navigate in the "News" tab, switch to the about tab and hit "About", and switch back to the News tab, leaving off right where you were, in both scroll position and path. In my app, I'm using version 1.1.2 of
@modus/ionic-vue
, as it does not require a router for tabs. The way I have this working is that each tab has its ownVueRouter
running inabstract
mode. This shouldn't be possible in other navigation modes, as going back should not change tabs. Other apps, such as the ionic-vue-conference-app, try to implement this, but fail badly. Other than being broken by using relative paths, switching between tabs doesn't retain the previous navigated path. This is a key feature in many apps, and is holding me back to this old version. See this demo of what I currently have, which is what I want. What is the proper way to do this?The text was updated successfully, but these errors were encountered: