I have my following routes.jsx
import React from 'react';
import { Route, Router, IndexRoute } from 'react-router';
import ReactDOM from 'react-dom';
import App from './index.jsx';
import Test1 from './test1.jsx';
import Test2 from './test2.jsx';
import TestWrapper from './wrapper.jsx';
import url from './url.json';
var routes = url.url.map(function(el){
return (<Route key={el} path={el} component={Test1} />);
});
ReactDOM.render((
<Router>
<Route path="/" component={App} >
{routes}
</Route>
</Router>
), document.getElementById('app'));
I am going to have a list of projects that will be using always the same component hence:
var routes = url.url.map(function(el){
return (<Route key={el} path={el} component={Test1} />);
});
and a test1.jsx as follow:
import React from 'react';
import data from './data.json';
class Test1 extends React.Component {
render () {
return (
<div>
// if is route "title1" load title1
// if is route "title2" load title2
// if is route "title3" load title3
</div>
);
}
}
export default Test1;
my url.json is:
{
"url": [
"title1",
"title2",
"title3",
"title4",
"title5"
]
}
I am fairly new to react, how can I pass to "test1" content based on the url? Ideally I will have a separate json file for the content.. Ex. if I am on localhost:8080/title1 I would like content loaded only for title1.