指定ルートのすべての子ルートのレイアウトをあらかじめ設定する方法でルートをネストしようとしています。例えば反応ルータでネストされたレイアウトルーティングコンポーネントを作成する方法は?
:この場合
<Provider store={store}>
<Router history={history}>
<Router path="/" component={Init}>
<Router component={LayoutThreeCol}>
<IndexRoute component={PageContainer}/>
</Router>
<Router component={LayoutTwoCol}>
<Route path="/example" component={Example}/>
<Route path="/another" component={Another}/>
</Router>
</Router>
</Router>
</Provider>
、LayoutThreeCol
とListTwoCol
子コンテナとプレゼンテーションコンポーネントをカプセル化する2つのレイアウト・コンポーネントです。 私は子要素に小道具を渡すだけでなくレンダリングもできる必要がありますが、私はエラーが発生しています。しかし、問題は、次の行をそれぞれ2つのコンポーネントの子と親にネストすることによって発生すると考えられます。ここ
`{React.cloneElement({...this.props}.children, {...this.props})}`
So here is the code I am using an init file to instantiate the `mapStateToProps`
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux';
import * as actionCreators from './ActionCreators'
import App from './App';
function mapStateToProps(state, ownProps){
return{
Items: state.feedItems,
universalNav: state.universalNav,
height: state.height,
width: state.width,
isMobile: state.isMobile,
isTablet: state.isTablet
};
}
function mapDispatchToProps(dispatch){
return bindActionCreators(actionCreators, dispatch);
}
const Init = connect(mapStateToProps, mapDispatchToProps)(App);
export default Init;
私はここラッパーとして
export default class App extends Component {
render(){
return(
<div>
<NavContainer />
{React.cloneElement({...this.props}.children, {...this.props})}
</div>
);
}
}
を使用するアプリケーション・ファイルであるレイアウトファイルの一例です。
export default class LayoutThreeCol extends Component{
render(){
return(
<div className="layout-3-col">
<div className="layout-3-col-left">
//stuff goes here
</div>
<div className="layout-3-col-center">
{React.cloneElement({...this.props}.children, {...this.props})}
</div>
<div className="layout-3-col-right">
//stuff goes here
</div>
</div>
)
}
}
レイアウト2 COL エクスポートデフォルトクラスLayoutTwoColは、コンポーネント延び{ は(レンダリング){ リターン(簡潔 ために省略 //) } }
、ページコンテナはAであります些細なプレゼンテーションコンポーネント。 上記の例のように、複数のネストされたコンポーネントをレンダリングするにはどうすればよいですか? ありがとう
ルータの設定は非常に混乱します。これは1つのパス ''/''しか持たないためです。これらのネストされたルータでより多くのコンポーネントをロードするトリガを期待しています..また、 'Router'をラップするだけで子コンポーネントは' Route'にする必要があります – azium
私はあなたの質問に答えましたか?もしそうなら、あなたは私の答えを受け入れることができますか?そうでない場合は、何が間違っているか教えてください。 – AlexB