Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/witty-vans-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': major
---

fix: navigate without reloading for links with a `target` attribute and will display in the current browsing context
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function get_link_info(a, base, uses_hash_router) {

const external =
!url ||
!!target ||
(target || '_self') !== '_self' ||
is_external_url(url, base, uses_hash_router) ||
(a.getAttribute('rel') || '').split(/\s+/).includes('external');

Expand Down
4 changes: 4 additions & 0 deletions packages/kit/test/apps/basics/src/routes/routing/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
<a href="/routing/b" data-sveltekit-reload>b</a>

<div class="hydrate-test"></div>

<a href="/routing/a?target" target="_self">_self</a>
<a href="/routing/a?target" target="_parent">_parent</a>
<a href="/routing/a?target" target="_top">_top</a>
26 changes: 26 additions & 0 deletions packages/kit/test/apps/basics/test/cross-platform/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,32 @@ test.describe('Routing', () => {
expect(requests.filter((url) => !url.endsWith('/favicon.png'))).toEqual([]);
});

test('navigates to a new page without reloading when `target` is the current browsing context', async ({
app,
page,
clicknav
}) => {
const targets = ['_self', '_parent', '_top'];

for (const target of targets) {
await page.goto('/routing');

await app.preloadData('/routing/a?target').catch((e) => {
// from error handler tests; ignore
if (!e.message.includes('Crashing now')) throw e;
});

/** @type {string[]} */
const requests = [];
page.on('request', (r) => requests.push(r.url()));

await clicknav(`a[target="${target}"]`);
expect(await page.textContent('h1')).toBe('a');

expect(requests.filter((url) => !url.endsWith('/favicon.png'))).toEqual([]);
}
});

test('navigates programmatically', async ({ page, app }) => {
await page.goto('/routing/a');
await app.goto('/routing/b');
Expand Down
Loading