#Statically exported client router seems to ignore `trailingSlash: true`

1 messages · Page 1 of 1 (latest)

cobalt raftBOT
#

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

#

Based on the knowledge sources provided, it appears that there are indeed some issues with the trailingSlash: true configuration in Next.js, particularly when used with static exports and client-side routing. Let me address your concerns:

  1. Regarding the client router ignoring trailingSlash: true:
    This seems to be a known issue. According to Github Issue #24483 (https://github.com/vercel/next.js/issues/24483), there are discrepancies between how trailing slashes are handled in development and production environments, especially with static exports.

  2. The behavior you're experiencing with the client router making requests without trailing slashes:
    This aligns with the issue described in Github Issue #62740 (https://github.com/vercel/next.js/issues/62740), where prefetch strategies for static deploys don't properly handle trailing slashes.

  3. Regarding the index.txt file:
    The presence of this file is part of Next.js's prefetching strategy. However, as noted in the same issue (#62740), these files are not versioned or hashed, which can lead to caching problems and inconsistent behavior.

  4. The href in the index.txt without a trailing slash:
    This does indeed seem to be inconsistent with the trailingSlash: true configuration. It's likely related to the issues mentioned above and could be considered a bug.

To address your specific question: Yes, with trailingSlash: true, the href in the index.txt should have a trailing slash. The fact that it doesn't suggests that the trailingSlash configuration is not being consistently applied across all parts of the Next.js build and runtime processes.

These issues seem to be more pronounced in static export scenarios, especially when deployed to platforms like AWS S3, as in your case.

#

While there isn't a definitive fix mentioned in the knowledge sources, some users have reported success by manually adding trailing slashes to their <Link> components, e.g., <Link href="/path/"> instead of <Link href="/path">. However, this is more of a workaround than a proper solution.

Given the complexity of this issue and its interaction with various Next.js features (static export, client-side routing, prefetching), it would be advisable to report this specific scenario to the Next.js GitHub repository as it may help the developers address these inconsistencies in future releases.

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