mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix(i18n): pass search params to fallback (#12547)
* fix(i18n): pass search params to fallback * test(i18n): add test for search param fix * test(i18n): resolve mantainer comments
This commit is contained in:
parent
dec0305b75
commit
6b6e18d7a0
5 changed files with 30 additions and 3 deletions
5
.changeset/kind-mayflies-argue.md
Normal file
5
.changeset/kind-mayflies-argue.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a bug where URL search parameters weren't passed when using the i18n `fallback` feature.
|
|
@ -375,9 +375,9 @@ export function redirectToFallback({
|
|||
}
|
||||
|
||||
if (fallbackType === 'rewrite') {
|
||||
return await context.rewrite(newPathname);
|
||||
return await context.rewrite(newPathname + context.url.search);
|
||||
} else {
|
||||
return context.redirect(newPathname);
|
||||
return context.redirect(newPathname + context.url.search);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
---
|
||||
const currentLocale = Astro.currentLocale;
|
||||
const search = Astro.url.search.toString()
|
||||
---
|
||||
|
||||
<html>
|
||||
|
@ -8,5 +9,6 @@ const currentLocale = Astro.currentLocale;
|
|||
</head>
|
||||
<body>
|
||||
Oi essa e start: {currentLocale}
|
||||
Search: {search}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
---
|
||||
const search = Astro.url.search
|
||||
---
|
||||
<html>
|
||||
<head>
|
||||
<title>Astro</title>
|
||||
</head>
|
||||
<body>
|
||||
Start
|
||||
Search: {search}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as cheerio from 'cheerio';
|
||||
import * as assert from 'node:assert/strict';
|
||||
import { after, afterEach, before, describe, it } from 'node:test';
|
||||
import * as cheerio from 'cheerio';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
|
@ -1582,6 +1582,22 @@ describe('[SSR] i18n routing', () => {
|
|||
assert.equal(response.status, 404);
|
||||
});
|
||||
|
||||
it('should pass search to render when using requested locale', async () => {
|
||||
let request = new Request('http://example.com/new-site/pt/start?search=1');
|
||||
let response = await app.render(request);
|
||||
assert.equal(response.status, 200);
|
||||
const text = await response.text();
|
||||
assert.match(text, /Oi essa e start/);
|
||||
assert.match(text, /search=1/);
|
||||
});
|
||||
|
||||
it('should include search on the redirect when using fallback', async () => {
|
||||
let request = new Request('http://example.com/new-site/it/start?search=1');
|
||||
let response = await app.render(request);
|
||||
assert.equal(response.status, 302);
|
||||
assert.equal(response.headers.get('location'), '/new-site/start?search=1');
|
||||
});
|
||||
|
||||
describe('with routing strategy [pathname-prefix-always]', () => {
|
||||
before(async () => {
|
||||
fixture = await loadFixture({
|
||||
|
|
Loading…
Reference in a new issue