mirror of
https://github.com/microsoft/playwright.git
synced 2024-11-28 01:15:10 +03:00
test(svelte): migrate svelte-navigator to custom minimal router (#30225)
Repro: `cd tests/components/ct-svelte && rm -rf node_modules package-lock.json && npm i && npx playwright test --project=chromium` Follow-up based on https://github.com/microsoft/playwright/pull/28624#issuecomment-1858608101. Svelte has no router by default, only SvelteKit - so lets remove the package which is not maintained anymore and not recommended.
This commit is contained in:
parent
345240b9df
commit
18b51308ff
@ -18,12 +18,6 @@
|
||||
"vite": "^5.0.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"svelte": "^4.2.8",
|
||||
"svelte-navigator": "^3.2.2"
|
||||
},
|
||||
"overrides": {
|
||||
"svelte-navigator": {
|
||||
"svelte": "$svelte"
|
||||
}
|
||||
"svelte": "^4.2.8"
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { Link, Route, Router } from "svelte-navigator";
|
||||
import logo from './assets/svelte.png'
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import LoginPage from './pages/LoginPage.svelte';
|
||||
import DashboardPage from './pages/DashboardPage.svelte';
|
||||
|
||||
let path = '';
|
||||
function updatePath() {
|
||||
path = window.location.pathname;
|
||||
}
|
||||
onMount(() => {
|
||||
updatePath();
|
||||
window.addEventListener('popstate', updatePath);
|
||||
});
|
||||
onDestroy(() => {
|
||||
window.removeEventListener('popstate', updatePath);
|
||||
});
|
||||
/**
|
||||
* @param newPath {string}
|
||||
*/
|
||||
function navigate(newPath) {
|
||||
history.pushState({}, '', newPath);
|
||||
updatePath();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
<header>
|
||||
<img src="{logo}" alt="logo" width="125" height="125" />
|
||||
<Link to="/">Login</Link>
|
||||
<Link to="/dashboard">Dashboard</Link>
|
||||
</header>
|
||||
<Route path="/*">
|
||||
<Route component="{LoginPage}" />
|
||||
<Route path="dashboard" component="{DashboardPage}" />
|
||||
</Route>
|
||||
</Router>
|
||||
<header>
|
||||
<a on:click={(e) => { e.preventDefault(); navigate('/'); }} href='/login'>Login</a>
|
||||
<a on:click={(e) => { e.preventDefault(); navigate('/dashboard'); }} href='/dashboard'>Dashboard</a>
|
||||
</header>
|
||||
{#if path === '/'}
|
||||
<LoginPage />
|
||||
{:else if path === '/dashboard'}
|
||||
<DashboardPage />
|
||||
{/if}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 5.1 KiB |
@ -19,12 +19,6 @@
|
||||
"sirv-cli": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"svelte": "^4.2.8",
|
||||
"svelte-navigator": "^3.2.2"
|
||||
},
|
||||
"overrides": {
|
||||
"svelte-navigator": {
|
||||
"svelte": "$svelte"
|
||||
}
|
||||
"svelte": "^4.2.8"
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { Link, Route, Router } from "svelte-navigator";
|
||||
<script>
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import LoginPage from './pages/LoginPage.svelte';
|
||||
import DashboardPage from './pages/DashboardPage.svelte';
|
||||
|
||||
let path = '';
|
||||
function updatePath() {
|
||||
path = window.location.pathname;
|
||||
}
|
||||
onMount(() => {
|
||||
updatePath();
|
||||
window.addEventListener('popstate', updatePath);
|
||||
});
|
||||
onDestroy(() => {
|
||||
window.removeEventListener('popstate', updatePath);
|
||||
});
|
||||
/**
|
||||
* @param newPath {string}
|
||||
*/
|
||||
function navigate(newPath) {
|
||||
history.pushState({}, '', newPath);
|
||||
updatePath();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
<header>
|
||||
<Link to="/">Login</Link>
|
||||
<Link to="/dashboard">Dashboard</Link>
|
||||
</header>
|
||||
<Route path="/*">
|
||||
<Route component="{LoginPage}" />
|
||||
<Route path="dashboard" component="{DashboardPage}" />
|
||||
</Route>
|
||||
</Router>
|
||||
<header>
|
||||
<a on:click={(e) => { e.preventDefault(); navigate('/'); }} href='/login'>Login</a>
|
||||
<a on:click={(e) => { e.preventDefault(); navigate('/dashboard'); }} href='/dashboard'>Dashboard</a>
|
||||
</header>
|
||||
{#if path === '/'}
|
||||
<LoginPage />
|
||||
{:else if path === '/dashboard'}
|
||||
<DashboardPage />
|
||||
{/if}
|
||||
|
Loading…
Reference in New Issue
Block a user