猿问

react4怎么嵌套路由啊?我的二级路由没有显示,也不报错是怎么回事?

下面是首页路由的配置


class RouterMap extends React.Component {

    render() {

        return (<BrowserRouter><div>

            <Switch>

            <Route path='/' exact component={Home}/>

             <Route path="/users" component={Users}/>

            <Route path='/city' component={City}/>

            <Route path='/city2' component={City2}/>

            <Route path='/result' component={Result}/>

            <Route match='match' path='/dashboard' exact component={Dashboard}/>

            <Route path='/dashboard/id'  component={Dashboard200}/>

            </Switch>

        </div></BrowserRouter>)

    }

}

下面是子路由页面的配置


class Dashboard extends React.Component {

    componentDidMount(){

        //console.log(this.props)

    }

    render() {

        console.log(this.props)

        const match=this.props.match

        return (<div>

            <div>123</div>

            <Switch>

                <Route path={`${match.url}/2`} component={Dashboard6}/>

                <Route path={`${match.url}/3`} component={Dashboard1}/>

                <Route path="/2" component={Dashboard1}/>

            </Switch>

         </div>)

    }

}


Helenr
浏览 3365回答 2
2回答

蓝山帝景

谢谢啊,已经解决了,主要是不能有exact,
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答