I make react router app. But I have an error. I can not identify it. I am new react developer.
My app code is:
export default function App() {
return (
<BrowserRouter className='bodyMy'>
<HeardTitle />
<Navbar />
<Switch>
<Route exact path="/" component={Card} />
<Route exact path="/class" component={Card2} />
</Switch>
</BrowserRouter>
);
}
and my navbar code:
export default function navbar() {
return (
<Fragment className='myNavbar'>
<ul>
<li >
<NavLink activeStyle={{ color:'green', fontWeight: "bold" }} exact to="/">Function</NavLink>
</li>
<li >
<NavLink activeStyle={{ color:'red', fontWeight: "bold" }} exact to="/class">Class</NavLink>
</li>
<li >
<NavLink href="#pricing">Logout</NavLink>
</li>
</ul>
</Fragment>
)
}
It shows TypeError: Cannot read property 'pathname' of undefined
asked Aug 10, 2021 at 3:04
1 Answer 1
In navbar change
<NavLink href="#pricing">Logout</NavLink>
to
<NavLink to="#pricing">Logout</NavLink>
answered Aug 10, 2021 at 6:16
Sign up to request clarification or add additional context in comments.
Comments
default
export default function Navbar()capital N since you make the component in the app.js something like this<Navbar />