Comments (9)
Also, interestingly, examples that don't use data router on StackBlitz appear to work fine so this seems to be something specific to data routers.
The auth example doesn't have this issue:
https://stackblitz.com/github/remix-run/react-router/tree/main/examples/auth
from react-router.
@brophdawg11 Maybe a regression from things changed around the time of #10005?
from react-router.
What version of vite
are you using? The error stack comes from vite
middleware so I'm not sure if this is related to RR code?
It also doens't look like it happens on Vite 5 - I crewated a brand new vite app from https://vitejs.dev/guide/#trying-vite-online and added a data router and trailing double slashes don't cause an issue:
https://stackblitz.com/edit/vitejs-vite-uwqys1
from react-router.
Oh dang, it looks like the error is different on StackBlitz than it is on my own apps. Sorry, I should've double checked that. Let me see if I can get a minimum repro based off my apps. The stack trace I get does point to node_modules/@remix-run/router/dist/router.js
as the origin of the error
from react-router.
The error comes from using the navigate function provided by useNavigate
or the Navigate
component. Please see this StackBlitz: https://stackblitz.com/edit/vitejs-vite-ht64rf?file=src%2FHomePage.jsx
Navigation with either button will work initially, but if you add the double slash to the url in the preview pane, both of them will stop working. Your browser console will display the error.
from react-router.
We'll look into this in #11924 but I think in general I would recommend doing some app-level detection of these invalid URLs and trigger a hard reload to get the user back to a valid URL:
let { pathname, search, hash} = window.location
if (pathname.includes('//')) {
window.location = pathname.replace(/\/{2,}/, '/') + search + hash
} else {
hydrateRoot(el, <App />);
}
I'm curious the use-case is where you end up with a double slash in the first place?
from react-router.
Nothing in my application will cause this, but it's something a user can do if they felt like it. Which I guess someone did, because I have a Sentry error event with this error, haha.
from react-router.
If this is one singular occurrence from one user who seems to have manually manipulated the URL and gotten an error page, I'm not sure it's something that needs to be addressed at the React Router level to try to correct/sanitize invalid URLs. Can you fix this with the suggestion in #11911 (comment)?
from react-router.
That's a fair point. I personally don't mind if you don't address this. I just wanted to report it because it's an unhandled error. I forgot to acknowledge it but the suggested solution is perfectly acceptable to me and I'm already using it so thank you for that.
from react-router.
Related Issues (20)
- [Bug]: Navlink className function props not work as expected it HOT 2
- [Docs]: Switched parameters in matchPath HOT 1
- [Bug]: Unable to match a url that ends in an equal sign HOT 1
- [Bug]: optional segments with dynamic segments HOT 1
- [Bug]: State is not preserved in a component tree when switching to render via custom `<Routes location={location}>` prop
- [Bug]: undefined is not an object (evaluating ' request.signal.aborted ')
- [Bug]: Relative option is not work in useNavigate HOT 3
- [Bug]: (a11y)-Multiple accessibility issues with React-Router HOT 1
- [Bug]: The global state manager does not work in conjunction with react-router-dom HOT 1
- [Bug]: encoded # in path parameter causes route to be evaluated differently
- [Bug]: generatePath/matchPath don't handle encoding/decoding `/` the same HOT 1
- [Bug]: Support non-standard HTTP methods in Resource Routes HOT 3
- [Bug]: react-router seems to depend on vulnerable versions of path-to-regexp HOT 8
- [Bug]: react-router-dom v5 uses vulnerable version of path-to-regexp HOT 6
- [Bug]: Mount happens twice on forward navigation HOT 2
- [Bug]: type errors with `exactOptionalPropertyTypes` HOT 5
- [Bug]: React-router does not work with react 18, besides using router v6.12.0 HOT 1
- [Bug]: ScrollRestoration doesn't restore horizontal page scroll HOT 1
- [Bug]: Component does not load for JSX-returning arrow functions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-router.