dream icon indicating copy to clipboard operation
dream copied to clipboard

Handle trailing `/` in routes

Open asymmetric opened this issue 1 year ago • 6 comments

Currently, one has to separately handle the presence/absence of trailing slashes, by having a route for "", and one for "/".

I think it would be more intuitive if a trailing slash were automatically added, or removed, via redirects.

For the record, Go's serveMux does the former.

asymmetric avatar Dec 11 '24 17:12 asymmetric

IIRC Dream sticks to the RFCs in treating these differently, as, IIRC, "" refers to a file-like resource and "/" to a directory. It may be a little old-fashioned. This could be a good use case for a middleware.

aantron avatar Dec 11 '24 19:12 aantron

Maybe we could introduce a small new addition to the Dream path syntax to handle an optional trailing slash, eg /foo:/ could match against both /foo and /foo/?

yawaramin avatar Dec 22 '24 19:12 yawaramin

I was working on middleware for a project and noticed "Router path access is being removed from the API."

Dream.path and Dream.with_path both are showing this error.

Is there a way to handle this with the functions still available?

briangwaltney avatar Dec 26 '24 06:12 briangwaltney

I guess with Dream.target

yawaramin avatar Dec 26 '24 15:12 yawaramin

Duplicate of #125?

yawaramin avatar Aug 10 '25 21:08 yawaramin

Not quite, they are just on similar topics.

aantron avatar Aug 11 '25 02:08 aantron