Can I have the same route for two routes

I defined these two routes:

<Route name='register' handler={Register} > <Route name='registerpromotion' path='/registerpromotion/:promotionCode' handler={Register}/> </Route> 

Thus, both routes use the same handler called Register.

In the case of the registerpromotion route, I pass the property and in the case of the register route, I do not.

I could not get this to work - the promotionCode property is always undefined.

Does anyone know if you can use the same handler for two routes?

Many thanks!

+5
source share
1 answer

This code is from answer-router No. 410 from rpflorence:

 /** @jsx React.DOM */ var React = require('react'); var Router = require('react-router'); var Route = Router.Route; var Routes = Router.Routes; var Link = Router.Link; var Foo = React.createClass({ render: function() { return ( <div> <p>hello</p> <p>stuffId: {this.props.params.stuffId}</p> <ul> <li><Link to="root">top</Link></li> <li><Link to="stuff" params={{stuffId: 'one'}}>one</Link></li> <li><Link to="stuff" params={{stuffId: 'two'}}>two</Link></li> </ul> <this.props.activeRouteHandler /> </div> ); } }); var routes = ( <Routes> <Route name="root" path="/" handler={Foo}> <Route name="stuff" path=":stuffId" handler={Foo}/> </Route> </Routes> ); React.renderComponent(routes, document.body); 
0
source

Source: https://habr.com/ru/post/1204632/


All Articles