0
我試圖使用反應路由器側邊欄例如:https://reacttraining.com/react-router/web/example/sidebar反應路由器側邊欄例如瞭解
const routes = [
{
path: '/',
exact: true,
sidebar:() => <div>home!</div>,
main:() => <h2>Home</h2>
},
{
path: '/bubblegum',
sidebar:() => <div>bubblegum!</div>,
main:() => <App />
},
{
path: '/shoelaces',
sidebar:() => <div>shoelaces!</div>,
main:() => <Felix />
},
{
path: '/processes',
sidebar:() => <div>shoelaces!</div>,
main:() => <Processes />
}
]
ReactDOM.render((
<Router history={hashHistory}>
<div>
<div style={{display: 'flex'}}>
<div style={{
padding: '10px',
width: '40%',
background: '#f0f0f0'
}}>
<ul style={{listStyleType: 'none', padding: 0}}>
<li><Link to="/">Homse</Link></li>
<li><Link to="/bubblegum">Bubblegum</Link></li>
<li><Link to="/shoelaces" activeClassName="active">Shoelaces</Link></li>
<li><Link to="/processes" activeStyle={{ color: 'red' }}>processbbes</Link></li>
</ul>
{routes.map((route, index) => (
<Route
key={index}
path={route.path}
exact={route.exact}
component={route.sidebar}
/>
))}
</div>
<div style={{flex: 1, padding: '10px'}}>
{routes.map((route, index) => (
// Render more <Route>s with the same paths as
// above, but different components this time.
<Route
key={index}
path={route.path}
exact={route.exact}
component={route.main}
/>
))}
</div>
</div>
</div>
</Router>
), document.getElementById('root'))
,到目前爲止,工作正常。
但我怎麼定義我的容器產生額外的路線,其不重新加載頁面,並在側邊欄未顯示?
如何將const路徑放在外部文件中?
這是一種使用react-router的可行方式嗎?