Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routeRules are sensitive to trailing slashes #2146

Closed
danielroe opened this issue Feb 11, 2024 · 10 comments
Closed

routeRules are sensitive to trailing slashes #2146

danielroe opened this issue Feb 11, 2024 · 10 comments
Labels
bug Something isn't working route-rules upstream

Comments

@danielroe
Copy link
Member

Environment

stackblitz

Reproduction

https://stackblitz.com/edit/github-yjju3h?file=nitro.config.ts,routes/index.ts,routes/sponsors.ts

Describe the bug

when a route rule is defined with a reproduction, this does not apply if a trailing slash is appended to the request:

export default defineNitroConfig({
  routeRules: {
    '/support-me': { redirect: { to: '/sponsors', statusCode: 301 } },
  }
})

Requesting /support-me works fine but /support-me/ does not redirect.

Additional context

No response

Logs

No response

@lwpinion

This comment was marked as off-topic.

@manniL manniL changed the title routeRules redirection is sensitive to trailing slash routeRules redirection is sensitive to trailing slash and casing Feb 16, 2024
@lpinion-ew

This comment was marked as off-topic.

@pi0 pi0 changed the title routeRules redirection is sensitive to trailing slash and casing routeRulesare sensitive to trailing slashes Mar 8, 2024
@pi0 pi0 changed the title routeRulesare sensitive to trailing slashes routeRules are sensitive to trailing slashes Mar 8, 2024
@pi0 pi0 added enhancement New feature or request discussion and removed pending triage labels Mar 8, 2024
@pi0

This comment was marked as off-topic.

@lwpinion
Copy link

lwpinion commented Mar 8, 2024

(Discussions about trailing slash and case sensitivity behavior are different. I have splitter case sensitivity to #2234 @lwpinion/@lpinion-ew you can follow from there for case differences)

Great. Thanks!

The current issue I mentioned a few minutes ago actually pertains more to the trailing slash. As a workaround, I think I could switch to using router.options within the context of Nuxt instead.

@pi0
Copy link
Member

pi0 commented Mar 8, 2024

I have investigated it a little more. It seems a bug in upstream radix3 matcher to be solved: unjs/radix3#87


As a temporary workaround, you might need to duplicate route rules

@pi0 pi0 added bug Something isn't working upstream and removed enhancement New feature or request discussion labels Mar 8, 2024
@lwpinion
Copy link

lwpinion commented Mar 8, 2024

I have investigated it a little more. It seems a bug in upstream radix3 matcher to be solved: unjs/radix3#87

As a temporary workaround, you might need to duplicate route rules:

export default defineNitroConfig({
  routeRules: {
    '/support-me': { redirect: { to: '/sponsors', statusCode: 301 } },
    '/support-me/': { redirect: { to: '/sponsors', statusCode: 301 } },
  }
})

That is the weird thing. I have duplicated the route rules, but for some reason the one without the trailing slash works and not the one with.

Check out these links:
https://www.easyworship.com/BonjourInstall
https://www.easyworship.com/BonjourInstall/

And here are the routeRules:

'/BonjourInstall': { redirect: { to: 'https://support.apple.com/kb/DL999?locale=en_US', statusCode: 303 } },
'/BonjourInstall/': { redirect: { to: 'https://support.apple.com/kb/DL999?locale=en_US', statusCode: 303 } },

Any idea as to why there is a discrepancy in how these are working? And if this is not the best place to troubleshoot this, please point me in the right direction. :-)

@manniL
Copy link
Member

manniL commented Mar 8, 2024

@lwpinion can you try a local build and check if the problem isn't the platform?

@pi0
Copy link
Member

pi0 commented Mar 8, 2024

(i can confirm problem is not local) Lets track via unjs/radix3#87

@lwpinion
Copy link

lwpinion commented Mar 8, 2024

Indeed. The problem does seem to occur locally for me as well.

@pi0
Copy link
Member

pi0 commented Mar 8, 2024

fixed with radix3 1.1.1: https://github.com/unjs/radix3/releases/tag/v1.1.1

confirmed on reproduction.

@pi0 pi0 closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working route-rules upstream
Projects
None yet
Development

No branches or pull requests

5 participants