1

I'm developing am application with ReactJS, but I have a problem.

That's my Router

<Router history={browserHistory}>
    <Route name="Home" path="/" component={App}>
        <IndexRoute component={Home}></IndexRoute>
        <Route name="Stores" path='stores' component={Stores}>
        <Route name="List" path='/stores/list' component={StoreList}></Route>
        <Route name="Create" path='/stores/create' component={StoreCreate}>   </Route>
    </Route>
    <Route name="404: No Match for route" path="*" component={NoMatch} />
    </Route>
</Router>

The route to Stores Don't exists. But, when I click in the link to this route, they must redirect do "StoreList"

<Route name="Stores" path='stores' component={Stores}>

So I did:

    class Stores extends React.Component {

      componentWillMount() {
        this.setUrlParameters();
      }

      setUrlParameters() {
        if (!this.props.children) {
          this.context.router.push({
              pathname: '/stores/list',
              query: {
                  page: 1,
                  limit: 10
              }
          });
        }
      }

      render() {
        return (this.props.children);
      }
    }

The first time that I click in the link, they do perfect the redirect. But if I click again, they not call componentWillMount and the redirect doesn't exec.

Can someone help me?

dinotom
  • 4,990
  • 16
  • 71
  • 139
Luiz Fumes
  • 41
  • 6

1 Answers1

0

try calling this.setURlParameters() in componentDidUpdate instead of componentWillMount

QoP
  • 27,388
  • 16
  • 74
  • 74