Trailing slashes on root pages return 404
See original GitHub issueIs your feature request related to a problem? Please describe. Accessing root pages with a trailing slash (often how links get formatted in applications and sites we push them out to) returns the 404 page.
Describe the solution you’d like I can see that Next@9.4.5, which is currently in canary, solves or at least addresses this problem, so hopefully this is something that can be maintained here as well, if the next update brings with it some additional resources to manage by this component.
Describe alternatives you’ve considered
We have tried supplying a set of hard redirects in next.config.js using “exportPathMap”, which works locally but not when deployed using the serverless-next.js component. We have considered adding another lambda@edge to the CloudFront inputs that can trim the slash before landing into the component’s routing logic, however that would increase latency. We have also considered just re-uploading the routing logic and altering the normaliseUri
function to trim the trailing slash before the page manifest is searched by the uri, which is a wooden solution obviously (second to forking this project for altering that one function).
Thank you for any insight on this! Any stopgap ideas would be very appreciated as well.
Relevant pull request here https://github.com/serverless-nextjs/serverless-next.js/pull/448
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:15 (4 by maintainers)
Top GitHub Comments
This is available now (and various bugs should be fixed), please try out the latest alpha (1.17.0-alpha.9) and let us know if there are issues.
My plan was to leave this one for you 😃
From what I see, it will not be copy/pasta of #448, but similar. This is the Next-side of the implementation for this task: https://github.com/vercel/next.js/pull/13333 The driving force for this feature will be whether the
experimental.trailingSlash=true
value is set in the deploying Next.js project’snext.config.js
. As the lambdas are stateless, you will want to persist this configuration to the manifest.json (this is typed as OriginRequestDefaultHandlerManifest) - this will be done in lambda-at-edge/build.ts. The trailingSlash handling logic should live in the default lambda (default-handler.ts)… I’m undecided whether it’s needed for the api lambda too. Next.js handles the trailingSlash stuff using https://github.com/vercel/next.js/blob/canary/packages/next/client/normalize-trailing-slash.ts (there were some fixes since the original PR was released).