0

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
  • I think it should be export default function Navbar() capital N since you make the component in the app.js something like this <Navbar /> Commented Aug 10, 2021 at 4:43

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.