鍍金池/ 問(wèn)答/HTML5  HTML/ react-router 如何實(shí)現(xiàn) vue-router 中 router-vi

react-router 如何實(shí)現(xiàn) vue-router 中 router-view 的功能

頁(yè)面路由切換的時(shí)候,只有部分組件重新渲染,在 vue-router 中,可以通過(guò) router-view 實(shí)現(xiàn),
想問(wèn)下在 react-router 中怎么實(shí)現(xiàn)。

回答
編輯回答
貓小柒

這可能會(huì)有所幫助: 192.168.0.1

2017年7月27日 09:52
編輯回答
瘋浪

首先,版本是3還是4.

下面說(shuō)下3的做法。

3里面route是可以嵌套的,如下

<route component={A}>
    <route path="/A/B" component={B}/>
    <route path="/A/C" component={C}/>
</route>

而A組件的寫(xiě)法通常如下

class A extends React.Component {
    render(){
        return (
            <div>{this.props.children}</div>
        )
    }
}

這里的children在不同路由下對(duì)應(yīng)不同組件,即/A/C對(duì)應(yīng)C組件,/A/B對(duì)應(yīng)B組件。

也就是說(shuō),要變化的寫(xiě)在B、C組件內(nèi),不變化的寫(xiě)在A組件內(nèi)。

2018年5月2日 23:26