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.

navigate() returns TypeError when using RegExp as route path

See original GitHub issue

I’ve been using Navigo for quite some time in a custom React wrapper. Until now, using RegExp as route path instead of strings worked perfectly. After upgrading from 7.1.2 to 8.8.0 this week, Navigo.navigate() however sometimes throws a TypeError exception

TypeError: t.replace is not a function. (In 't.replace(/\/+$/,"")', 't.replace' is undefined)

This happens, when a RegExp is provided to matchLocation() as first argument and this value is run through clean() function, which expects a String. Since replace() isn’t available on RegExp objects, the above exception is thrown.

Enclosing the same RegExp routes definitions in strings works without any problem.

It would also be great, if capture groups in RegExp route definitions would be evaluated and added to Match.data object.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
krasimircommented, Jan 30, 2021

Thanks. I’ll invetstigate.

1reaction
mritzerfeldcommented, Feb 2, 2021

It seems indeed to be a problem with babel which I’ll have to investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pillarjs/path-to-regexp: Turn a path string such as `/user - GitHub
The pathToRegexp function will return a regular expression object based on the provided path argument. It accepts the following arguments: path A string ......
Read more >
React-router-dom Redirect not working - shows error
So, you can install path-to-regexp module(npm i path-to-regexp) in the application and restart the application. Everything will work fine.
Read more >
generatePath - React Router: Declarative Routing for React.js
The generatePath function can be used to generate URLs to the routes. Internally the path-to-regexp library is used. Results of compiling paths into...
Read more >
react-router - UNPKG
1, {"version":3,"file":"react-router.min.js","sources":["../../node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","../.
Read more >
String.prototype.matchAll() - JavaScript - MDN Web Docs
Each match is an array with the same shape as the return value of RegExp.prototype.exec() . Exceptions. TypeError. Thrown if the regexp is...
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