react router @4 和 vue路由 详解(三)react如何在路由里面定义一个子路由

完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html

5、react如何在路由里面定义一个子路由?

 
  a、引入在需要子路由的页面引入Route标签  
 
   <Route path='/noteDetail/home' component={NodeDe} />

  b、举个?(糖炒栗子,我的爱,为什么我自己做的?都那么难吃???)

 

    

 

    我们在home页面里(左边一溜的父组件)该点击的地方

复制代码
export const Home = () => (
  <ul>
    <li>
      <NavLink to='/home' exact activeStyle ={selectedStyle}>首页</NavLink>
    </li>
    <li>
      <NavLink to='/about' activeStyle ={selectedStyle}>关于我们</NavLink>
    </li>
    <li>
      <NavLink to='/event' activeStyle ={selectedStyle}>企业事件</NavLink>
    </li>
    <li>
      <NavLink to='/product' activeStyle ={selectedStyle}>公司产品</NavLink>
    </li>
    <li>
      <NavLink to='/us' activeStyle ={selectedStyle}>联系我们</NavLink>
    </li>
  </ul>
)
复制代码

     我们在home页面里(左边一溜的父组件)设置内容应该不同的地方

复制代码
      <Redirect exact from="/" to="/home"></Redirect>
      <Route path='/home' exact component={Home}/>
      <Route path='/about' component={About}/>
      <Route path='/event' component={Event}/>
      <Route path='/product' component={Product}/>    
      <Route path='/us' component={Us}/>    
复制代码

 

    我们在关于我们页面该点击的地方

复制代码
export const AboutMenu = () => (
  <ul className="about-menu">
    <li>
      <NavLink to='/about' exact activeStyle ={selectedStyle}>公司简介</NavLink>
    </li>
    <li>
      <NavLink to='/about/history' activeStyle ={selectedStyle}>公司历史</NavLink>
    </li>
    <li>
      <NavLink to='/about/services' activeStyle ={selectedStyle}>公司服务</NavLink>
    </li>
    <li>
      <NavLink to='/about/location' activeStyle ={selectedStyle}>企业位置</NavLink>
    </li>
  </ul>
)
复制代码

    我们在关于我们页面该实现内容不同的地方

      <Route path='/about' exact component={Company}/>
      <Route path='/about/history' component={History}/>
      <Route path='/about/services' component={Services}/>
      <Route path='/about/location' component={Location}/>

 

    由此便实现了react子路由

转载于:https://www.cnblogs.com/yangyangxxb/p/10074787.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值