我试图真正理解路由如何与我的反应应用程序上的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