2
我想創建一個佈局分量將會使頭和頁腳。所以,我可以在以後使用佈局像ReactJS頁眉和頁腳
<Layout> ... </Layout>
我在頁眉和頁腳使用的路由,效果顯着。要做到這一點,我需要使用
<Router history...
<Route path...
當我做這一個接一個:在我layout.js(頁眉和頁腳,雖然我覺得這是錯誤的)。有用。頁眉和頁腳顯示在瀏覽器中。 但是,它們不能正常工作。在刷新時,頁腳消失,有時也會消失,頁眉和頁腳。我堅信,一個接一個地渲染路由器是造成這種故障的原因,但我無法弄清楚正確的方法。此外,我不想用
header.js
import React from 'react';
import {Link} from 'react-router'
import {Navbar, NavItem} from 'react-materialize';
export default React.createClass({
render(){
return (
<div>
<Navbar brand='logo' right>
<NavItem><Link to="/Home" activeClassName="active">Home</Link></NavItem>
<NavItem><Link to="/Sign-In" activeClassName="active">Sign In</Link></NavItem>
<NavItem><Link to="/Register" activeClassName="active">Register</Link></NavItem>
</Navbar>
{this.props.children}
</div>
)
}
})
footer.js
import React, {Component} from 'react';
import {Link} from 'react-router'
import {Footer} from 'react-materialize';
import '../../resource/template.css'
class RT_Footer extends Component{
render(){
return (
<div>
{this.props.children}
<Footer copyrights="© 2015 Copyright Text"
moreLinks={
<Link className="grey-text text-lighten-4 right" href="#!">More Links</Link>
}
links={
<ul>
<li><Link to="/About Us" className="grey-text text-lighten-3">About Us</Link></li>
<li><Link to="/Terms & Conditions" className="grey-text text-lighten-3">Terms & Conditions</Link></li>
<li><Link to="/Help" className="grey-text text-lighten-3">Help</Link></li>
<li><Link to="/Contact Us" className="grey-text text-lighten-3">Contact Us</Link></li>
</ul>
}
className='example'
>
<h5 className="white-text">Footer Content</h5>
<p className="grey-text text-lighten-4">You can use rows and columns here to organize your footer content.</p>
</Footer>
</div>
);
}
}
export default RT_Footer;
layout.js
import {Router, Route, browserHistory} from 'react-router'
class Layout extends Component {
render(){
return (
<div>
<span>
<Router history={browserHistory}>
<Route path="/" component={Header}>
<Route path="/Home" component={Home}/>
<Route path="/Sign-In" component={SignIn}/>
<Route path="/Register" component={Register}/>
</Route>
</Router>
</span>
<span>
<Router history={browserHistory}>
<Route path="/" component={RT_Footer}>
<Route path="/About Us" component={About}/>
<Route path="/Terms & Conditions" component={TC}/>
<Route path="/Register" component={Register}/>
</Route>
</Router>
</span>
</div>
);
}
}
export default Layout;
然後,我只是呈現佈局在index.js
隨意紀念這個爲解決Ø r評論:) – Quentin
我試圖解決它,但徒勞無功。你的回答非常有幫助。 Jus給我一天。我會再次嘗試使其工作。 – Roy
感謝哥們! :) – Roy