Skip to content

Commit ebe0b80

Browse files
fix(svelte): remove svelte-navigator from repository (#221)
* Remove svelte-navigator * add missing hash for initial state + theme from query --------- Co-authored-by: Vladimir Kharlampidi <[email protected]>
1 parent 6c5b7eb commit ebe0b80

File tree

6 files changed

+32
-180
lines changed

6 files changed

+32
-180
lines changed

kitchen-sink/react/components/App.jsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import routes from '../routes.js';
66
import HomePage from '../pages/Home.jsx';
77

88
function App() {
9-
const [theme, setTheme] = useState('ios');
9+
const [theme, setTheme] = useState(
10+
window.location.search.includes('theme=material') ? 'material' : 'ios'
11+
);
1012
const [currentColorTheme, setCurrentColorTheme] = useState('');
1113
const setColorTheme = (color) => {
1214
const htmlEl = document.documentElement;

kitchen-sink/svelte/components/App.svelte

+23-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<script>
2-
import { onMount, beforeUpdate } from 'svelte';
2+
import { onMount, onDestroy, beforeUpdate } from 'svelte';
33
import { App } from 'konsta/svelte';
4-
import { Router, Route, createHistory } from 'svelte-navigator';
5-
import createHashSource from '../hashHistory.js';
64
75
import routes from '../routes.js';
86
import HomePage from '../pages/Home.svelte';
97
10-
let theme = 'ios';
8+
let theme = window.location.search.includes('theme=material') ? 'material' : 'ios';
119
const setTheme = (t) => {
1210
theme = t;
1311
};
@@ -42,29 +40,36 @@
4240
}
4341
};
4442
43+
let hash = window.location.hash || '';
44+
function updateHash() {
45+
hash = window.location.hash;
46+
}
47+
4548
onMount(() => {
4649
calcSafeAreas();
50+
window.addEventListener('popstate', updateHash);
4751
});
4852
4953
beforeUpdate(() => {
5054
calcSafeAreas();
5155
});
5256
53-
const hash = createHistory(createHashSource());
57+
onDestroy(() => {
58+
window.removeEventListener('popstate', updateHash);
59+
});
60+
61+
$: component = routes.find(route => route.path === hash.slice(1))?.component;
5462
</script>
5563
5664
<App {theme} safeAreas={!inIFrame}>
57-
<Router history={hash} primary={false}>
58-
<Route path="/">
59-
<HomePage
60-
{theme}
61-
{setTheme}
62-
colorTheme={currentColorTheme}
63-
{setColorTheme}
64-
/>
65-
</Route>
66-
{#each routes as route}
67-
<Route path={route.path} component={route.component} />
68-
{/each}
69-
</Router>
65+
{#if component}
66+
<svelte:component this={component} />
67+
{:else}
68+
<HomePage
69+
{theme}
70+
{setTheme}
71+
colorTheme={currentColorTheme}
72+
{setColorTheme}
73+
/>
74+
{/if}
7075
</App>

kitchen-sink/svelte/hashHistory.js

-43
This file was deleted.

kitchen-sink/vue/components/App.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
kApp,
1313
},
1414
setup() {
15-
const theme = ref('ios');
15+
const theme = ref(
16+
window.location.search.includes('theme=material') ? 'material' : 'ios'
17+
);
1618
const currentColorTheme = ref('');
1719
const setColorTheme = (color) => {
1820
const htmlEl = document.documentElement;

package-lock.json

+2-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
"react-router-dom": "^6.26.1",
6565
"rollup": "^4.21.0",
6666
"svelte": "^5.0.0-next.241",
67-
"svelte-navigator": "^3.2.2",
6867
"tailwindcss": "^3.4.10",
6968
"vite": "^5.4.2",
7069
"vue": "^3.4.38",
@@ -73,4 +72,4 @@
7372
"dependencies": {
7473
"konsta": "file:src"
7574
}
76-
}
75+
}

0 commit comments

Comments
 (0)