Description
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 own VueRouter
running in abstract
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?
Activity
mattsteve commentedon Jan 7, 2020
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
ion-vue-router
.Vue Router Named Views:
https://router.vuejs.org/guide/essentials/named-views.html
Router config
lights0123 commentedon Jan 12, 2020
@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
ion-nav
, so I get native-like swipe-to-go-back behavior on iOS. I used vue-custom-element and vue-fragment to make that work.michaeltintiuc commentedon Apr 25, 2020
@lights0123 thanks for sharing your implementation, sorry for not replying earlier. Could you share your implementation using
ion-nav
? I am working on the tabs functionality for the Vue 3 version and was considering a router with a stack of history states or something along those lines and I was thinking of back-porting it to the upcoming 2.0.0 version as well. I just don't want to force people into using a custom router, I'd rather have them work with something they're accustom tolights0123 commentedon Apr 25, 2020
@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:
A router:
Each page has:
Once, to initialize that:
This setup has a few advantages:
<ion-nav>
basically does the same thing as<keep-alive>
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.
michaeltintiuc commentedon Apr 25, 2020
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
michaeltintiuc commentedon Jul 9, 2020
You can give a try with the vue 3 version,
npm i @modus/ionic-vue@next
it's not separate routers per tab as that's not quite possible with Vue or even web history as the end of the day, but the behavior is much closer to what is expectedaileksandar commentedon Aug 7, 2020
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
michaeltintiuc commentedon Aug 7, 2020
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
children
prop:Note that we're using
RouterView
withinIonTabs
as we don't need any transitions and just want a route switch, withinIonTab
we're usingIonRouterView
to leverage transitions.aileksandar commentedon Aug 7, 2020
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
https://github.com/meoweloper/ionic-vue-3
michaeltintiuc commentedon Aug 7, 2020
@meoweloper Please see this PR against your repo https://github.com/meoweloper/ionic-vue-3/pull/1
The tabs work, but you pointed out a type-o in the router outlet, I'm going to release a new version ASAP, thank you!
Please note that swipe-back currently does not have a limit to itself, meaning that you can swipe back past the tab's root route, the fix is in the works, the router will have separate history states for each tab and one for global navigation
michaeltintiuc commentedon Aug 7, 2020
See version
3.0.0-alpha.14
should be available in a bitaileksandar commentedon Aug 7, 2020
Glad to hear that separate history is in the works, I think thats the missing piece that will push tabs to a beta state.
aileksandar commentedon Aug 7, 2020
I found that same issue component type, just didn't know how to fix it 👶 ⌨️
michaeltintiuc commentedon Aug 8, 2020
Are you saying you get the same error?
aileksandar commentedon Aug 8, 2020
No, you fixed it in alpha.14. Just saying I failed to fix it myself.
michaeltintiuc commentedon Aug 8, 2020
It was a library issue that I introduced some time ago, it's on me :)