Skip to content

Commit 7586143

Browse files
florian-lefebvreascorbicjsparkdevsarah11918
authored
[v6] trailing slash never for endpoints with file extension (#12467)
Co-authored-by: Matt Kane <m@mk.gg> Co-authored-by: Junseong Park <to@jspark.dev> Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
1 parent e840333 commit 7586143

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/content/docs/en/guides/endpoints.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import type { APIRoute } from "astro";
4747
export const GET: APIRoute = async ({ params, request }) => {...}
4848
```
4949

50+
Note that endpoints whose URLs include a file extension (e.g. `src/pages/sitemap.xml.ts`) can only be accessed without a trailing slash (e.g. `/sitemap.xml`), regardless of your [`build.trailingSlash`](/en/reference/configuration-reference/#trailingslash) configuration.
51+
5052
### `params` and Dynamic routing
5153

5254
Endpoints support the same [dynamic routing](/en/guides/routing/#dynamic-routes) features that pages do. Name your file with a bracketed parameter name and export a [`getStaticPaths()` function](/en/reference/routing-reference/#getstaticpaths). Then, you can access the parameter using the `params` property passed to the endpoint function:

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Check that both your development environment and your deployment environment are
8989

9090
### Vite 7.0
9191

92+
<SourcePR number="14445" title="feat: update vite"/>
93+
9294
Astro v6.0 upgrades to Vite v7.0 as the development server and production bundler.
9395

9496
#### What should I do?
@@ -377,6 +379,8 @@ In most cases, the only action needed is to review your existing project's deplo
377379

378380
### Changed: `i18n.routing.redirectToDefaultLocale` default value
379381

382+
<SourcePR number="14406" title="feat(astro)!: update i18n.redirectToDefaultLocale default"/>
383+
380384
In Astro v5.0, the `i18n.routing.redirectToDefaultLocale` default value was `true`. When combined with the `i18n.routing.prefixDefaultLocale` default value of `false`, the resulting redirects could cause infinite loops.
381385

382386
In Astro v6.0, `i18n.routing.redirectToDefaultLocale` now defaults to `false`. Additionally, it can now only be used if `i18n.routing.prefixDefaultLocale` is set to `true`.
@@ -404,6 +408,25 @@ export default defineConfig({
404408

405409
The following changes are considered breaking changes in Astro v5.0. Breaking changes may or may not provide temporary backwards compatibility. If you were using these features, you may have to update your code as recommended in each entry.
406410

411+
### Changed: endpoints with a file extension cannot be accessed with a trailing slash
412+
413+
<SourcePR number="14457" title="feat!: trailing slash never for endpoints with file extension"/>
414+
415+
In Astro v5.0, custom endpoints whose URL ended in a file extension (e.g. `/src/pages/sitemap.xml.ts` ) could be accessed with a trailing slash (`/sitemap.xml/`) or without (`/sitemap.xml`), regardless of the value configured for `build.trailingSlash`.
416+
417+
In Astro v6.0, these endpoints can only be accessed without a trailing slash. This is true regardless of your `build.trailingSlash` configuration.
418+
419+
#### What should I do?
420+
421+
Review your links to your custom endpoints that include a file extension in the URL and remove any trailing slashes:
422+
423+
```html del={1} ins={2} title="src/pages/index.astro"
424+
<a href="/sitemap.xml/">Sitemap</a>
425+
<a href="/sitemap.xml">Sitemap</a>
426+
```
427+
428+
<ReadMore>Learn more about [custom endpoints](/en/guides/endpoints/).</ReadMore>
429+
407430
## Community Resources
408431

409432
Know a good resource for Astro v5.0? [Edit this page](https://github.com/withastro/docs/edit/main/src/content/docs/en/guides/upgrade-to/v6.mdx) and add a link below!

0 commit comments

Comments
 (0)