-
Notifications
You must be signed in to change notification settings - Fork 230
Fix matching routes with trailing slash (refs #532) #727
Conversation
Relevant backbone discussion: jashkenas/backbone#848 |
I think we should instead redirect users from trailing-slash-URLs to non-trailing-slash-URLs (can be disabled in config). What do you think?
No mess with SEO. |
👍 |
Can you also please handle |
@@ -77,6 +77,13 @@ module.exports = class Route | |||
value = params[name] | |||
url = url.replace ///[:*]#{name}///g, value | |||
|
|||
# Add or remove trailing slash according to options | |||
switch @options.trailing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about if @options.trailing isnt false
? A switch on a boolean seems a bit weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, going further if @options.trailing is true
is even simpler ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we want null
/undefined
to set trailing to true also. The only time we don't want it true is when trailing is false, hence trailing isnt false
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the referenced issue #532 setting values other than true
or false
would perform no redirecting whatsoever. That would be also my semantic understanding (yes
–add a slash, no
—remove it, null
/undefined
—abstain from action).
@paulmillr You mean in the tests? Right now there's a default setting |
I'll check it! |
Awesome. Can you please squash all commits to one and i'll merge this? |
Implementation is consistent with the one proposed in chaplinjs#532
Voila! :) |
Fix matching routes with trailing slash (refs #532)
Thanks dude — this is awesome |
Hi,
It's an attempt to fix non-functioning routes when using trailing slash. I stumbled upon it while testing my app with urls like http://app-domain.dev/recipes vs http://app-domain.dev/recipes/, where in the latter case Chaplin doesn't recognise my routes anymore.
My
routes.js.coffee
: