leiyanting

导航

 
                1.注册子路由时要写上父路由的path值
                2.路由的匹配是按照注册路由的顺序进行的
import React, { Component } from 'react'
import MyNavLink from '../../components/MyNavLink'
import {Route,Switch,Redirect} from 'react-router-dom'
import News from './News'
import Message from './Message'

export default class Home extends Component {
    render() {
        return (
                <div>
                    <h3>我是Home的内容</h3>
                    <div>
                        <ul className="nav nav-tabs">
                            <li>
                                <MyNavLink to="/home/news">News</MyNavLink>
                            </li>
                            <li>
                                <MyNavLink to="/home/message">Message</MyNavLink>
                            </li>
                        </ul>
                        {/* 注册路由 */}
                        <Switch>
                            <Route path="/home/news" component={News}/>
                            <Route path="/home/message" component={Message}/>
                            <Redirect to="/home/news"/>
                        </Switch>
                    </div>
                </div>
            )
    }
}

 

posted on 2022-01-11 08:22  leiyanting  阅读(45)  评论(0编辑  收藏  举报