Skip to content

Commit

Permalink
use pushState for redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 23, 2022
1 parent e7f44dc commit e28bc39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 4 additions & 5 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,10 @@ export class Renderer {
});
} else {
if (this.router) {
this.router.goto(
new URL(navigation_result.redirect, info.url).href,
{ replaceState: true },
[...chain, info.url.pathname]
);
this.router.goto(new URL(navigation_result.redirect, info.url).href, {}, [
...chain,
info.url.pathname
]);
} else {
location.href = new URL(navigation_result.redirect, location.href).href;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1635,14 +1635,17 @@ test.describe.parallel('searchParams', () => {
});

test.describe.parallel('Redirects', () => {
test('redirect', async ({ baseURL, page, clicknav }) => {
test('redirect', async ({ baseURL, page, clicknav, back }) => {
await page.goto('/redirect');

await clicknav('[href="/redirect/a"]');

await page.waitForURL('/redirect/c');
expect(await page.textContent('h1')).toBe('c');
expect(page.url()).toBe(`${baseURL}/redirect/c`);

await back();
expect(page.url()).toBe(`${baseURL}/redirect`);
});

test('prevents redirect loops', async ({ baseURL, page, javaScriptEnabled }) => {
Expand Down

0 comments on commit e28bc39

Please sign in to comment.