ITADN

Story links do not respect the trailingSlash configuration in astro.config.mjs

#162Closedadesege 创建于 2025-08-13
A
adesegecommented
**Describe the bug** The `astrobook` integration currently generates story URLs without considering the `trailingSlash` setting in the host project's `astro.config.mjs`. When `trailingSlash: 'always'` is enabled in an Astro project, this discrepancy leads to 404 "Not Found" errors in the development environment and unnecessary 3xx redirects in production builds. **Current Behavior** If `trailingSlash` is set to `'always'` in `astro.config.mjs`, `astrobook` generates links without a trailing slash (e.g., `/stories/my-story`). - **In Development (`astro dev`):** Clicking this link results in a **404 error** because the dev server expects a URL with a trailing slash (e.g., `/stories/my-story/`). - **In Production (`astro build`):** Clicking the link works, but it first triggers a **server-side redirect** to the correct path that includes the trailing slash. This is inefficient and not ideal for performance or SEO. **Expected Behavior** `astrobook` should read the final resolved Astro configuration and generate links that respect the `trailingSlash` setting. - If `trailingSlash: 'always'`, generated links should consistently include a trailing slash (e.g., `/stories/my-story/`). - If `trailingSlash: 'never'`, generated links should not include a trailing slash. - The generated links should resolve directly without causing 404s or redirects in either the development or production environment. **Steps to Reproduce** 1. Set up a new Astro project and integrate `astrobook`. 2. In `astro.config.mjs`, add the `trailingSlash` option: ```javascript import { defineConfig } from 'astro/config'; export default defineConfig({ trailingSlash: 'always' }); ``` 3. Create any story file, such as `src/stories/Button.story.astro`. 4. Run the development server with `npm run dev`. 5. Navigate to the Astrobook UI. 6. Observe the link for the "Button" story in the navigation menu. It will be missing the trailing slash. 7. Click the link and confirm that it leads to a 404 page. **Possible Solution** The integration should access the final, resolved Astro config within the `astro:config:setup` hook and pass the `trailingSlash` value to the client-side UI. The UI can then use this value to construct the correct URLs for the story links.
关闭于 2025-08-14 2 条评论