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.

Support more characters in path part matchers

See original GitHub issue

The current code for matching path segments to route props is quite simple: the regex: /:[a-zA-Z]+/. In at least one instance this surprised a user. As @coodoo points out This could be expanded to the following valid URL characters

; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #

Since changing this is a breaking change for the library I am opening an issue to invite discussion on the topic.

The way I see it none of the following characters belong in a JS variable, so they should not be part of the route prop matcher.

; , / ? : @ & = +  - . ! ~ * ' ( ) #

That leaves: $ _. I think as part of a regex using $ could be confusing, and I also think its probably unlikely to be wanted. That leaves only _. I am willing to create a breaking change to add this, but only once there is critical mass for it. Breaking changes are a cost to the userbase, and I don’t want to charge that cost if the benefit is to less than 5% of the users. Of course, I don’t have a good way to poll, or even a good idea of how big the user base is, but I do have a good handle on the number of people active on this repository and its about 10. So if I can get 3 people who want a breaking change in order to have underscores in route props I will make the change.

I will leave the issue open for 1 year, or until that happens, whichever comes first. Of course, the floor is still open for anyone that wants to defend one of the characters I didn’t like.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
n33pmcommented, Nov 8, 2022
const routes = {
  "/users/:userId": ({ userId }) => <div>{userId}</div>,
  "/users/:userId_test": ({ userId }) => <div>{userId}</div>
};

currently the second route would match with /users/n33pm_test and userId = n33pm. after the change userId_test = n33pm_test and userId is undefined and both routes would match the same. probably it breaks ?!

1reaction
kyeoticcommented, Nov 10, 2022

Sorry @coodoo I thought I responded to this, but I must not have hit enter.

It’s a breaking change because routes that match with an underscore will get a different variable passed in as a route parameter. That is the front-door API for the entire library, and changing the output like that would cause a previously functioning route to start failing. I know it seems like a minor addition to a regex, but that regex is the API for useRoutes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ant path style patterns - java - Stack Overflow
Ant-style path patterns matching in spring-framework: The mapping matches URLs using the following rules: ? matches one character; * matches zero or more...
Read more >
Using Wildcards in Paths | Sumo Logic Docs
is a simple, non-recursive wildcard representing zero or more characters which you can use for paths and file names.
Read more >
Examples of wildcard characters - Microsoft Support
Wildcards are special characters that can stand in for unknown characters in a text value and are handy for locating multiple items with...
Read more >
isaacs/minimatch: a glob matcher in javascript - GitHub
Compare a partial path to a pattern. As long as the parts of the path that are present are not contradicted by the...
Read more >
Chrome Extensions Match patterns
In the path section, each ' * ' matches 0 or more characters. The following table shows some valid patterns.
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