I am new to reactjs
and I have a small project in reactjs
to play and learn it. I need to have a type of headers to be shown based on the urls. So this is my index.js that handles routing:
const history = useRouterHistory(createHistory)({ basename: '/test' }) class Tj extends React.Component { render() { return ( <Router history={history}> <Route path={"/"} component={Bridge} > <IndexRoute component={Home} /> <Route path={"user"} component={T} /> <Route path={"home"} component={Home} /> </Route> <Route path={"/t/"} component={Bridge2} > <IndexRoute component={T} /> <Route path={"contact"} component={Home} /> </Route> </Router> ); } } render( <Provider store={store}> <Tj/> </Provider>, window.document.getElementById('mainContainer'));
As you can see, I use test as the root directory and based on user input for url. I decide which title to use. Also here is Bridge2.js :
export class Bridge2 extends React.Component { render() { return ( <div> <div className="row"> <Header2/> </div> <div className="row"> {this.props.children} </div> </div> ); } }
and Bridge.js :
export class Bridge extends React.Component { render() { // alert(this.props.children.type); var Content; if(this.props.children.type){ Content=<div> <div className="row"> <Header/> </div> <div className="row"> {this.props.children} </div> </div>; } else{ Content=<div> <div className="row"> <Header/> </div> <div className="row"> {this.props.children} </div> </div>; } return ( Content ); } }
When I run this on the webpack dev server everything works fine. For example, when I use http://localhost:3003/test/
, the bridge.js file is loaded, and if I run http://localhost:3003/test/t/
, the bridge2.js file is loaded, which is expected.
However, since the dev web package server is not a production server, I am using tomcat, and at the moment I am using the eclipse web application project, and I copied the bundle.js file and index.html there. Now the problem is that when I start the tomcat server, it is able to recognize and show this path:
http://localhost:8080/test/
, but when for http://localhost:8080/test/t/
we get:
HTTP Status 404 - / test / t /
which basically says the resource file is unavailable. As far as I understand, this is not a problem in coding, as routing works fine in the dev web package server, but when it comes to tomcat, it seems that the routing reaction is not able to handle it. Is there something wrong with what I'm doing? Is this done in general? Can anyone help?