Closed UnKnoWn-Consortium closed 5 years ago
Yeah, you have it right for the most part, the routing is broken due to how ion-tab-button
s are setup. By default the value of tab
is appended to the URL, this is as you've mentioned covering the most basic of use cases. To handle more advanced stuff, pass the to
property, which behaves the same way as the to
prop of router-link
This is from the ionic docs:
<!-- Provide extra data to route -->
<ion-tab-button tab="map" :to="{ name: 'app.map', params: { mode: 'dark' } }">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
The above will make it so when you click on the Map tab you would always be redirected to the app.map
route with specific params set. For this to work you should give your routes names.
In case if you'd like to have the same tab to be active for several routes you should set the routes
prop on ion-tab
s it could be a route name or an array of those. This will handle the route matching for you.
Also I'd move the routes such as search/:id
to be children of search/
I'm working on a proper example for tabs as it's the most confusing part of Ionic. Meanwhile I'd suggest checking out the usage docs for Vue: https://github.com/ionic-team/ionic/tree/master/core/src/components/tabs#vue
@michaeltintiuc
Oh crap, I have totally overlooked this doc.... https://github.com/ionic-team/ionic/tree/master/core/src/components/tabs#vue
Thank you very much for bringing it up... I have been reading the Ionic doc at https://ionicframework.com/docs/api/tab-button and kept on trying with the href
and tab
attributes mentioned there... both to no avail...
Thanks again for your reply and your help.
I have tried the following setup for the ion-tabs navigation. It is sort-of working for certain scenarios (e.g. navigating from
/home
to/home/about
or from/home
to/shop
) but things start to get awkward when I try to do "cross-tab" navigation (e.g. from/home
to/shop/1234
).When I am at
/shop/1234
, the tabs can no longer bring me back to/home
,/shop
, or/search
. It keeps on changing the path (e.g. from/shop/1234
to/shop/home
)... Have I got the router setup wrong?P.S. A repo replicating the situation will be added.