#Ensure trailing slash for getStaticPaths

3 messages · Page 1 of 1 (latest)

lyric apex
#

How can I ensure that routes generated by getStaticPaths will have a trailing slash?

normal knotBOT
#

Hi @lyric apex. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To ensure that routes generated by getStaticPaths in Astro have a trailing slash, you should configure the trailingSlash option in your astro.config.mjs file to 'always'. This setting will make Astro only match and generate URLs that include a trailing slash (e.g., /about/). In production, requests without a trailing slash will be redirected to the correct URL with a trailing slash.

Example configuration:

// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
  trailingSlash: 'always'
});

This will ensure that all statically generated routes, including those from getStaticPaths, will have a trailing slash in their URLs. Note that trailing slashes on prerendered pages are ultimately handled by your hosting platform, so check your platform’s documentation if you notice any inconsistencies Configuration Reference.

Additionally, if you are using the default build.format: 'directory', this will also align with trailing slash behavior, as Astro will generate directories with an index.html file for each route (e.g., /about/index.html maps to /about/Build Options.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: