我試圖用我的Django應用程序使用reactjs
和react-router
(1.x
),但我很難將所有這些放在一起。這是github項目,只是在這個問題中我沒有提供足夠的信息。404頁未找到使用Django + react-router
https://github.com/liondancer/django-cherngloong
我在我的routes.js
var routes = (
<Router>
<Route path="/" component={ Views.Layout }>
<IndexRoute component={ Views.Index } />
<Route path="about" component={ Views.About } />
</Route>
<Route path="*" component={ Views.RouteNotFound } />
</Router>
);
export default routes;
創建path="about"
我layout.js
class Layout extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div id="review-web">
<header className="header">
<LogoElement />
<CenterPiece />
</header>
<div>
{ React.cloneElement(this.props.children, { path: this.props.path }) }
</div>
<Footer />
</div>
);
}
}
export default Layout;
當我localhost.8000/about
進入我得到一個404
Django的錯誤
我的目標是保持前端和後端分離,所以我相信我應該能夠使用Django作爲數據端點而不是渲染視圖。
當你去「/」它成功地服務Views.Layout頁面嗎?對我來說,它看起來像你的應用程序不知道服務器或查看routes.js。你配置你的應用程序使用routes.js? – user2719875
@ user2719875現在我的應用程序使用[this](https://github.com/liondancer/django-cherngloong/blob/master/assets/js/index.js)來使用'route.js'。如果我要輸入'localhost:8000 /',它會顯示[this](https://github.com/liondancer/django-cherngloong/blob/master/assets/js/views/index.js)組件] – Liondancer
它可以工作,如果你這樣做: (參見我在路徑開頭使用的斜槓)。編輯:另外,你確定你不想在它自己包含「 」這一行嗎?它目前嵌套在其他路線內。 –
user2719875