Skip to content

Conversation

@alexdln
Copy link
Contributor

@alexdln alexdln commented Feb 1, 2026

Trailing slash setup. For example I often visit a page with a slash in the end and see a 404 error, even though the package exists. Now it will redirect.

I did this using vercel config. I'm a little concerned that this approach won't work during local development, but it seems better than leaving things as they are. Any better ideas would be appreciated [if needed]

Closes #648

@vercel
Copy link

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Feb 1, 2026 3:40pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Feb 1, 2026 3:40pm
npmx-lunaria Ignored Ignored Feb 1, 2026 3:40pm

Request Review

Copy link
Collaborator

@43081j 43081j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does work, so seems like a good change to me

to get it to work in dev, we'd need to configure nuxt's router.options.strict to false i think, but that seems to break other things. so for now, maybe we just don't bother in dev and figure it out in a separate PR

@danielroe
Copy link
Member

this is good

we can also add a global route middleware, dev only, which redirects

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

@danielroe
Does it make sense for us to do different approaches for dev and prod? Or should we always redirect through middleware?

@danielroe
Copy link
Member

it'll be more performant to do the cdn-level redirect as opposed to middleware

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

Done

@serhalp
Copy link
Collaborator

serhalp commented Feb 1, 2026

@danielroe can this not be accomplished with nitro routeRules?

(not a blocker!)
I was separately looking into self-hosting instructions for folks to deploy their own npmx instance and found quite a few Vercelisms to work through. This adds another. Is it a goal of this project to avoid these in the long term?

@danielroe
Copy link
Member

absolutely it should be self-hostable - I'm not aware of anything at all in the project that's vercel-specific though. 🤔

all the config for vercel cache is only enabled when deployed on vercel. that's why I extracted it into a module. you should be able to build + run locally with no issues.

this shouldn't add another, if done correctly.

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

It sounds like we should enable middleware not only for dev, but for non-Vercel

@danielroe
Copy link
Member

i think we have to be careful

there are some providers, like netlify(?) that add trailing slashes for static routes and cause infinite loops

maybe better to sanitise package name to remove slash on package page?

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

It's not ideal to have one page with two different paths. Plus, it might be a problem for search engines (npmx have canonical URLs, but redirects are still better)

Also, this will be a very targeted fix, but the problem will persist on all other pages and potentially flare up later

@danielroe
Copy link
Member

we should add a rel=canonical for sure

and we already have a util to extract thd package name from path. I think we just change that

I was also working on a PR to make Vue Router extract params which is ultimately what we'd want I think, but I'm blocked for now

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

To clarify: it would be better if we won't redirect, but instead show the correct page for both /package-name and /package-name/. And this would apply to all pages?

@danielroe
Copy link
Member

yes

there is a nuxt config option to respect trailing slashes but it has caused so many issues with some providers that I'd prefer to leave it off if we can

@alexdln
Copy link
Contributor Author

alexdln commented Feb 1, 2026

I've created a new PR (#673). Should we close this one or leave it for further discussion and a final decision?

@danielroe
Copy link
Member

I would merge this one too, as a nice-to-have

@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 2, 2026
@danielroe danielroe added this pull request to the merge queue Feb 2, 2026
Merged via the queue into npmx-dev:main with commit 4dd98d5 Feb 2, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure trailing slash redirects

4 participants