-
Notifications
You must be signed in to change notification settings - Fork 42
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
pattern.match
does not match wildcard paths appropriately if missing trailing slash
#24
Comments
hey nifty, the behaviour of your code snippet is intended! that there is no special behaviour for wildcards next to trailing slashes. this is on purpose. you can however make the slash and the wildcard optional by wrapping them in parentheses. this should do what you want: var UrlPattern = require('url-pattern');
var pattern = new UrlPattern('/snd/url-pattern(/*)');
console.log(pattern.match('/snd/url-pattern')); // returns `{}`
console.log(pattern.match('/snd/url-pattern/')); // returns `{_: ''}`
console.log(pattern.match('/snd/url-pattern/abc')); // returns `{_: 'abc'}` let me know if this solves your issue. |
Hey nifty, If you do care about SEO your 301 redirect approach is definitely the best. See this article Trailing slashes and SEO for a short explanation on why this is bad. |
@sh good to know, thank you 👍 |
If we have a route, such as
/snd/url-pattern
and we do not have a trailing forward slash (in other words, if the route is not/snd/url-pattern/
with the trailing/
), then it does not match the wildcard path of/snd/url-pattern/*
as it should. Here is a code snippet:The only possible idea I have right now to fix this is to use this middleware in order to automatically 301 redirect to trailing slashes https://github.com/avinoamr/connect-slashes.
Do you think you can fix this in your package, or is there a more appropriate way for me to do this?
The text was updated successfully, but these errors were encountered: