This is my app.js
import React from 'react'
import Quote from './components/Quote';
import './index.css'
import Abraham from './components/Abraham'
import {
BrowserRouter as Router,
Routes,
Route,
Link
} from "react-router-dom";
function App() {
return (
<>
<div>
<Quote />
<h2>List of authors</h2>
</div>
<Router>
<div>
<Link to="/">Author1</Link>
</div>
<Routes>
<Route exactpath="/" element={ <Abraham/>} />
</Routes>
</Router>
</>
)
}
export default App;
abraham.js
import React from 'react'
export default function Abraham() {
return (
<div>
<h1>My name is Abraham</h1>
</div>
)
}
I want to redirect to abraham when I click on author 1 but it is not happening. The page is not redirecting. I used React-Router-DOM to link it to another page which is Abraham
which I have imported.
2
Answers
I think you missed a space here between
exact path
, The exactpath prop should be written as exact path with a space between them. See on the documentation: https://v5.reactrouter.com/web/api/Route/exact-boolIf you would like for the
Abraham
route and component to be rendered separate from theQuote
component,h2
element, and links, then you should place the latter on a route so they are also conditionally rendered based on the URL path.There is no
exact
prop for theRoute
component in React-Router v6, it should be removed since all routes are now always exactly matched using a route ranking score.Example: