mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
Handle unmatched 404 when using prerender in dev mode (#5983)
* fix(#5975): unmatched static paths should 404 during dev * chore: add changeset Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
parent
03e374f6bc
commit
b53e0717b7
3 changed files with 10 additions and 1 deletions
5
.changeset/fluffy-cherries-shake.md
Normal file
5
.changeset/fluffy-cherries-shake.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a dev server edge case where prerender + getStaticPaths would not 404 on an unmatched route
|
|
@ -47,7 +47,7 @@ export async function getParamsAndProps(
|
|||
routeCache.set(route, routeCacheEntry);
|
||||
}
|
||||
const matchedStaticPath = findPathItemByKey(routeCacheEntry.staticPaths, params, route);
|
||||
if (!matchedStaticPath && !ssr) {
|
||||
if (!matchedStaticPath && (ssr ? mod.prerender : true)) {
|
||||
return GetParamsAndPropsError.NoMatchingStaticPath;
|
||||
}
|
||||
// Note: considered using Object.create(...) for performance
|
||||
|
|
|
@ -72,7 +72,9 @@ describe('prerender getStaticPaths - 404 behavior', () => {
|
|||
|
||||
it('resolves 404 on pattern match without static path - named params', async () => {
|
||||
const res = await fixture.fetch('/pizza/provolone-pineapple');
|
||||
const html = await res.text();
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
});
|
||||
|
||||
it('resolves 200 on matching static path - rest params', async () => {
|
||||
|
@ -82,7 +84,9 @@ describe('prerender getStaticPaths - 404 behavior', () => {
|
|||
|
||||
it('resolves 404 on pattern match without static path - rest params', async () => {
|
||||
const res = await fixture.fetch('/pizza/pizza-hut');
|
||||
const html = await res.text();
|
||||
expect(res.status).to.equal(404);
|
||||
expect(html).to.match(/404/);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue