I try to really understand how routes work with react-router on my react application and express on my node.js server.
React-router code :
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'));
My server routing:
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 );
});
my react routing works perfectly, however I want to make a AJAX call to fill my components. For this I try to get a JSON from my node server. However the path 'test' doesn't work. My console.log is not called.
I don't know why, I probably didn't understantd how it really works. How can I create easily webservice to prepare my AJAX call ?