Routing outside react component
Hello everyone, I would like to know if this is possible to be done:
- Outside the React components I have an header with two links
- Those links will redirect to Page1\Index.cshtml or PageTwo/Index.cshtml
- Those Index.cshtml have a layout and nothing to render for now...an app.js is loaded that do the rendering of those pages
- The app has this:
var $ = require('jquery'); require('materialize'); var React = require('react'); var ReactRouter = require('react-router'); var Router = ReactRouter.Router var Route = ReactRouter.Route var routes = require('./routes.jsx');
React.render(( routes ), document.querySelector('.view-area'));
in my routes.jsx I have:
var Page1 = require('./components/Page1.jsx'); var Page2 = require('./components/Page2.jsx'); var routes = (
<Router >
<Route path="Page1" component={Page1} />
<Route path="Page2" component={Page2} />
<Route path="/" component={Page1}/> //I don't have a main component so by default I put this
</Router>
);
What is happening is: When I click on those two links, it is always using the route with the path "/" and renders the Page1
My question is: Can I have react routing that redirects correctly without having a main route/main component? I'm just using react components at a certain point in my app, so those two links are not react components, they just come from a normal cshtml page.
Thanx in advance
After some research I answered this question myself: I Implemented the library history: var history = require('history') var createHistory = history.createHistory();
in my router:
<Router history={createHistory}>
Works great ;)