score:0
I uninstalled @types/react-router-dom and installed it back. The error went away, don't know the magic but it worked for me.
score:0
This may be a result of some confusions in node_modules
for multirepo projects with some integration approaches.
The simplest way to avoid problems is to keep only one node_modules
folder for all projects integrated together in one application. Otherwise some subproject can use different versions of same library (as example React or Router etc) which can be not compatible with each other in internal data structs (react contexts and so on) and that brings problems like this.
score:0
this is solved when you use <Router>
, just add outside </Router></AppProvider>
<BrowserRouter>
<Switch>
//sample route
<Route path="/index" render={(props) => <Index {...props} />} />
</Switch>
</BrowserRouter>
score:0
One possible issue is using 'React Router DOM' and 'React Router' simultaneously in package.json.
They are technically three different packages: React Router, React Router DOM, and React Router Native. The primary difference between them lies in their usage. React Router DOM is for web applications and React Router Native is for mobile applications made with React Native
score:6
A possible origin is answered in spanish Stackoverflow, its a typescript project.
Original post: https://es.stackoverflow.com/a/372161/24877
According to the React documentation, this usually happens by having the React duplicated (more than one copy of React) https://reactjs.org/warnings/invalid-hook-call-warning.html
Apparently when using the npm link
the application Try to use react from projects "react-app" and "react-app-components" and therefore when publishing it to the npm repository
the error no longer comes out.
To fix it I removed the dependencies react
, react-router-dom
from the package.json and rerun npm install
to remove the folders from node_modules.
package.json
Before:
{
//...
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.5",
"babel-loader": "^8.1.0",
"glob": "^7.1.6",
"react": "^16.13.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"source-map-loader": "^1.0.1",
"ts-loader": "^7.0.5",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"peerDependencies": {
"react": "^16.13.1",
"react-router-dom": "^5.2.0"
}
}
After:
{
//...
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@types/react": "^16.9.41",
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.5",
"babel-loader": "^8.1.0",
"glob": "^7.1.6",
"source-map-loader": "^1.0.1",
"ts-loader": "^7.0.5",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.12"
},
"peerDependencies": {
"react": "^16.13.1",
"react-router-dom": "^5.2.0"
}
}
I just leave the "@types" to work with typescript
score:15
Well you're using a NavLink outside of the BrowserRouter/HashRouter (whatever you're using)
You said it yourself
You should not use Link outside a Router
Make sure that you have the structure like this
// App render or whatever
render() {
return (
<BrowserRouter>
<NavigationBar />
{`whatever else you doin'`}
</BrowserRouter>
);
}
You must always render them inside a Router
score:72
Make sure you wrap the main react render code in the Router. For example, with react-dom you need to wrap the app in Browser-Router. If this is a Udacity project, this is typically the index.js file.
import { BrowserRouter } from 'react-router-dom';
ReactDOM.render(
<BrowserRouter>
<App />
</BrowserRouter>
, document.getElementById('root'));
Source: stackoverflow.com
Related Query
- You should not use Route or withRouter() outside a Router when using react-router 4 and styled-component in react
- Using React Router to load components You should not use <Link> outside a <Router>
- You should not use Route outside a Router after use of withRouter
- You should not use Link outside a Router using react-router-dom
- Error: Invariant failed: You should not use <Link> outside a <Router> when I try to test my app using localhost
- React Router problem with "Link", Error: Invariant failed: You should not use <Link> outside a <Router>
- Using withRouter in context provider results in error: "Invariant failed: You should not use <Route> outside a <Router>"
- You should not use Route outside a router
- Invariant failed: You should not use <Switch> outside a <Router> using Static Router
- When should you NOT use React memo?
- React Testing Library Invariant failed: You should not use <Route> outside a <Router>
- React - Error: Invariant failed: You should not use <Link> outside a <Router>
- React Typescript Error: Invariant failed: You should not use <withRouter(App) /> outside a <Router>
- MobX, React Router v4, Route using render function not observing and re-rendering when store changes
- CSS not changing when using React Router to route to another component
- When importing from a library, Invariant failed: You should not use <Route> outside a <Router>
- React jest - You should not use <Link> outside a <Router>
- Using Link in Mapbox GL JS popup throws Error: Invariant failed: You should not use <Link> outside a <Router>
- Error in withRouter params parsing Invariant Violation: You should not use <Route> or withRouter() outside a <Router>
- Link should be not be outside router error while using <Link> with <ListItem> in React rmwc
- You should not use <Route> or withRouter() outside a <Router> but Im in route
- When should you use render and shallow in Enzyme / React tests?
- Should you ever use this.setState() when using redux?
- You should not use <Link> outside a <Router>
- Jest, Enzyme: Invariant Violation: You should not use <Route> or withRouter() outside a <Router>
- Invariant Violation: You should not use <Switch> outside a <Router>
- Invariant failed: You should not use <Route> outside a <Router>
- Storybook w/ react-router - You should not use <Link> outside <Router>
- How to pass the match when using render in Route component from react router (v4)
- connected-react-router - You should not use <Route> outside a <Router>
More Query from same tag
- Highcharts-React Get Base64 PNG of chart
- window.addEventListener not updating state on route change when scrollY is not 0
- Unable to access the data from inside the For Loop from the outside of the For Loop
- redux state value returns undefined
- Invalid hook call. How to set a value with react axios get call?
- React redux display data from async action
- Passing down async fetched data via Context API
- how to update my current route state if component did update
- Right way to update state object in redux react native
- Test suits failed with "SyntaxError: Unexpected token 'export" ' react typescript using jest
- React changing state in Parent , does render calls for all its children and sub-children as iteration?
- Create input field by clicking a button
- How to add an active class to my navigation links React router?
- React: Setting state to local storage
- Jest mock for clone function
- react-virtualized Data Table Example
- Not able to change React state using useState
- Change css class of a component by onClick on Icon in React using useState hook
- Add a conditional error and success message on a panel based on required input fields are filled or not. If all fields are filled,"Done" should did
- State managed in Context is showing undefined
- How to access the redux store from a library?
- Converting string date in react/javascript
- How to stop the component from rendering before ajax call is completed in reactjs
- react native how to call multiple functions when onPress is clicked
- React functional component with mapped Child functional component with onClick function
- Django: Unsupported media type
- React.Component 'this' changed in ComponentDidMount
- Reactjs , .map function output variables error
- React property map issue
- js/reactjs - How do i reconstruct data from a json into a array?