question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Route tolerance for trailing slash

See original GitHub issue

ENVIRONMENT

$ yarn rw --version
0.0.1-alpha.31

PROBLEM

I’d like both /url and /url/ to match a single route.

Currently, if I use <Route path="/posts" ...> that will match URL /posts but not /posts/. If I change the route to <Route path="/posts/" ...>, it matches /posts/ but not /posts.

When using React-Router, this is easy to solve using a combination of the strict and exact parameters, something like <Route strict={false} exact={true} path="/posts/" ...>.

Is there an option to the Redwood Route object that controls tolerance for trailing slashes?

A regex for path-matching could also be a good approach.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mojombocommented, Feb 28, 2020

@chris-hailstorm It’s an artifact of the implementation that regex syntax currently works in routes. I expect that will go away so that we can do an optimized parser-based route matcher in the future, but I need to think about it more.

Regarding trailing slashes, we could add a trailingSlashes option on Router that could be one of:

never - Always strip trailing slashes from URLs before matching.
always - Always add trailing slashes to URLs before matching.
preserve - Keep trailing slashes as-is before matching.

Probably we would default to never. Would this solve your use case, or did you have some other requirement in mind?

1reaction
tctrautmancommented, Jan 4, 2021

Hello! I just ran up against this in one of my Redwood Projects. Just wanted to drop a note here to mention that I’d find this feature helpful, and I appreciate all that you all are doing to make Redwood awesome 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel - append a trailing slash in routes - Stack Overflow
Humm I think it looks possible through middleware eg. $ php artisan make:middleware slashesMiddleware.
Read more >
HTTP 301 Permanent Redirect Filter For URLs Without ...
By default, Spring MVC is tolerant and accepts requests to URL mappings with request URLs both ending with and without a trailing slash...
Read more >
failure to mount if a mount point ends with a slash in /etc/fstab
Here's why it fails to mount it: When systemd parses /etc/fstab, it trims the trailing slashes. When it comes to the mounting, ...
Read more >
hapi — Ignore Trailing Slashes on Route Paths - Future Studio
The problem of trailing slashes on route paths can be kind of annoying and different platforms generate both URL styles: with and without ......
Read more >
iRule to Add Trailing Slash Except for Extensions - DevCentral
iRule to Add Trailing Slash Except for Extensions ... { # Append slash and keep querystring when it exists HTTP::uri [HTTP::path]/[expr { "[URI::query ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found