我試圖真正理解路由如何與我的反應應用程序上的react-router一起工作,並在我的node.js服務器上表達。服務器端和客戶端的路由 - React.js&Node.js
陣營路由器代碼:
import ..
import { Router, Route, IndexRoute, hashHistory, IndexRedirect, Redirect } from "react-router";
render(
<Router history={hashHistory}>
<Redirect from="/" to="/index"/>
<Route path="/" component={App}>
<IndexRoute component={NavBarTop} />
<IndexRoute component={NavFilter} />
<Route path="/index" component={Tickets} />
<Route path="/ticket/:id" component={TicketInformations} />
<IndexRoute component={InterventionsList} />
</Route>
</Router>,
document.getElementById('container'));
我的服務器路由:
app.use('/', express.static(path.join(__dirname, '../client/')), function(res, eq) {
});
app.get('/test', function (req, res) {
console.log("test");
var data = getTickets(); // return a JSON
res.end(data);
});
我的反應路徑完美的作品,但是我希望做一個AJAX調用,以填補我的部件。爲此,我嘗試從我的節點服務器獲取JSON。然而,路徑「測試」不起作用。我的console.log沒有被調用。
我不知道爲什麼,我可能不知道它是如何工作的。 如何輕鬆創建web服務來準備我的AJAX調用?
哪裏是通話「/測試」? – sundar
在我的節點路由'app.get('/ test')' – onedkr
你必須從你的客戶端應用程序調用該API。另一個不會被稱爲 – sundar