score:1
Try these fixes:-
Since you use NavLink
inside MyAppNavBar.js
, then it will need BrowserRouter
from react-router-dom
to be functional.
Then you can either do:-
- Fixes 1 - Wrap everything in
App.js
withBrowserRouter
or, - Fixes 2 - You can just remove
BrowserRouter
inRoutes.js
You just need ONE BrowserRouter
anyway
Fixes 1
Remove
BrowserRouter
from bothindex.js
&Routes.js
add & wrap everything inside
App.js
withBrowserRouter
'index.js':-
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
ReactDOM.render(<App/>, document.getElementById('root')
);
Routes.js
:-
import React from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import Category from './Category';
import Products from './Products';
import Home from "./Home";
import About from "./About";
import NotFound from './NotFound'
const Routes = () =>
<Switch>
<Route exact path='/'>
<Home />
</Route>
<Route path='/about'>
<About />
</Route>
<Route path='/category'>
<Category />
</Route>
<Route path='/products'>
<Products />
</Route>
<Route >
<NotFound />
</Route>
</Switch>
export default Routes;
App.js
:-
import React, { Component } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import Routes from './website/Routes';
import MyAppNavbar from "./website/MyAppNavbar";
const App = () =>
<Router>
<MyAppNavbar />
<Routes/>
</Router>
export default App;
Fixes 2
Remove BrowserRouter
from Routes.js
Routes.js
:-
import React from 'react';
import { Switch, Route, Link } from 'react-router-dom';
import Category from './Category';
import Products from './Products';
import Home from "./Home";
import About from "./About";
import NotFound from './NotFound'
const Routes = () =>
<Switch>
<Route exact path='/'>
<Home />
</Route>
<Route path='/about'>
<About />
</Route>
<Route path='/category'>
<Category />
</Route>
<Route path='/products'>
<Products />
</Route>
<Route >
<NotFound />
</Route>
</Switch>
export default Routes;
Source: stackoverflow.com
Related Query
- Blank page is displayed instead of Bootstrap Navbar that I am trying to create with React Router
- navbar react router with bootstrap not working
- Bootstrap dropdown not working with React router
- Bootstrap 4 NavBar with React <Link/> component
- How to implement react routing with bootstrap navbar component?
- Trying to emulate Bootstrap navbar collapse/expand with React State
- React-bootstrap navbar with React Router
- Bootstrap Navbar with React
- I created a section to move between different parts of the site with the Router by NavBar in react
- React make navbar component with active class without react router (because of laravel routing)
- What's the correct way to render React components with different styles such as Navbar using React Router 6v?
- How to Change pages via react Router with Bootstrap Dropdown?
- Hidding Navbar with React Router V4
- Bootstrap v4 navbar , navbar-toggler-icon not working with react
- Navbar component location doesn't update when route changed, with React Router
- Hiding Navbar component with with React Router
- React bootstrap - how to make navBar with 100vh height when in mobile
- smooth scrolling with a bootstrap navbar in react js
- how to use nav link in react with router and bootstrap style
- React Router with optional path parameter
- Nested routes with react router v4 / v5
- Multiple params with React Router
- Material-UI's Tabs integration with react router 4?
- How to use React Router with Electron?
- How to fetch the new data in response to React Router change with Redux?
- React Router v4 with multiple layouts
- How to mock history.push with the new React Router Hooks using Jest
- Protected route with react router v6
- How to redirect from axios interceptor with react Router V4?
- How to let react router respond with 404 status code?
More Query from same tag
- How to avoid react rerendering whole tree on simple className changes?
- reactjs nullcheck before mapping through array of markers
- Why does React / NextJS still render the return if there is an IF to route?
- React + Redux - wait for action to end?
- Toggle state inside object using react hook
- How can I apply classNames in react to change the background color of one of the child div in React
- reactjs props not passed to child
- Uncaught SyntaxError: Unexpected token '!' reactjs mainchunk.js
- Redirection to dashboard after login in react
- setState doesn't update immediately, what is th best alternative way to do it?
- ReactJS - How to add in a removeEventListener when my mouse enters div element (onMouseEnter)
- How to map a JSON file from an API on React, selecting values to be added on a selector on product details
- Redirect after enter form react
- Navigating to a 404 Route with Reach Router
- Fileinput not defined
- how to assign variables to an object for submitting the Data using reactjs?
- Dropdown values not showing when I click dropdown button - Reactjs
- Checking if the values are greater than a certain number in cypress
- Is there a way to set input placeholder as props in react?
- 'TypeError: illegal operation attempted on a revoked proxy' when using Immer with setState
- How do I make requests to /wp-json/wp/v2/users/me after logging in? (401 error)
- react-redux: Call multiple apis parallely on componentDidMount
- Invariant Violation: Could not find "store" in either the context or props of "Connect(App)"
- react - useState never update the value
- how to check onclick function is fired or not in react?
- How to translate formik ErrorMessage with React i18next
- How to "override" the render function?
- Access is denied. Check credentials and try again, Microsoft graph API, update profile picture
- Problem with jquery(react-owl-carousel) in gatsby/react
- Importing dispatch actions to React Component assistance