Navlink路由导航,自带current简直太方便

zhuanbike 2022-1-3 740

function App() {
  return (
    <div className="App">
        <div>
          <NavLink to="/home">点我去home</NavLink>
          <NavLink to="/phone">点我去phone</NavLink>
          <NavLink to="/User">点我去User</NavLink>
        </div>
    <Switch>
    
      <Route path="/home" component={Home}/>
      <Route path="/phone" component={Phone}/>
      <Route path="/User" component={User}/>
      <Route path="/User" component={User}/>
      <Redirect from="/" to="/home/homea" exact/>
      </Switch>
    </div>
  );
}
export default App;


最新回复 (1)
  • zhuanbike 2022-1-3
    0 引用 2
    Navlink会直接给当前url的导航加一个 class="active" ,自带current属性,确实很不错。
发新帖