Skip to content

Commit ace9f0b

Browse files
TommertomTommertom
Tommertom
authored and
Tommertom
committed
Fixed IonTabs
1 parent a285891 commit ace9f0b

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log Ionic-Svelte-NPM
22
All notable changes to this project will be documented in this file.
33

4+
## 0.5.69
5+
- IonTabs - possibly breaking changes for users - fixed bug when tabs are placed in main route
6+
47
## 0.5.68
58
- added some typings for platform functions
69

components/IonTabs.svelte

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script>
2+
// @ts-nocheck
23
import { onMount } from "svelte";
34
import { page } from "$app/stores";
45
@@ -7,34 +8,25 @@
78
export let ionTabsDidChange = () => {};
89
export let ionTabsWillChange = () => {};
910
export let slot = "bottom";
11+
export let tabs = [];
1012
1113
let ionTabBarElement;
14+
let controller;
1215
13-
export let tabs = [];
16+
// we need relative path for the goto to function properly and to allow for relative tab definitions
17+
const { pathname } = $page.url;
18+
let currentTabName = pathname.split("/").at(-1); // we restrict tabs not to have nested paths
19+
const relativePath = pathname.replace(currentTabName, "");
1420
15-
let controller;
1621
onMount(async () => {
1722
// reassignment needed after onMount
1823
controller = ionTabBarElement;
19-
const { pathname } = $page.url;
20-
let tabInPathName = pathname.split("/").at(-1);
21-
22-
if (tabInPathName && tabs.length > 0) {
23-
// if we have don't have a route to a tab, let's take the first one
24-
if (!tabs.map((tab) => tab.tab).includes(tabInPathName)) {
25-
await goto(tabInPathName + "/" + tabs[0]?.tab);
26-
controller.select(tabs[0]?.tab);
27-
}
28-
} else {
29-
// panic - incorrect route or no tabs provided
30-
console.warn("Incorrect route or no tabs supplied for IonTabs", $page.url, tabs);
31-
goto("/");
32-
return;
33-
}
24+
controller.select(currentTabName);
3425
});
3526
3627
const tabBarClick = async (selectedTab) => {
37-
await goto(selectedTab);
28+
currentTabName = selectedTab;
29+
await goto(relativePath + selectedTab);
3830
controller.select(selectedTab);
3931
};
4032
</script>

index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ export function isPlatform(
7171

7272
export function testUserAgent(win: Window, expr: RegExp);
7373

74+
75+
// for people using tabs
76+
export interface TabListItem {
77+
label: string;
78+
icon: string;
79+
tab: string;
80+
}
81+
7482
// not exported by @ionic/core
7583
export type NavigationHookResult = boolean | NavigationHookOptions;
7684
export interface NavigationHookOptions {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ionic-svelte",
3-
"version": "0.5.68",
3+
"version": "0.5.69",
44
"private": false,
55
"homepage": "https://ionicsvelte.firebaseapp.com",
66
"repository": {

0 commit comments

Comments
 (0)