0

I have my roots defined like following:

<Route path="/" onEnter={this.verifyLang}>
  <Route path="/:lang" onEnter={this.verifyLang}>

    <IndexRoute component={this.getIndexRoute()} />
    <Route path="auth">
      <Route path="confirm-password" component={this.getIndexRoute()} />
      <Route path="confirm-code/code=:code&email=:email" component={this.getIndexRoute()}  />
      <Route path="confirm_email" component={this.getIndexRoute()}  />
    </Route>
    <Route path="landing" component={Landing} />
    <Route path="impress" component={Impress} />

  </Route>
</Route>

The function this.getIndexRoute() gives me Launch component. Now inside Launch component I have a method:

componentWillReceiveProps(nextProps){

    browserHistory.push('landing');
}

I am expecting to redirect to Landing component but nothing happens. Why it is so?

Thinker
  • 5,326
  • 13
  • 61
  • 137

1 Answers1

0

Instead of...

<IndexRoute component={this.getIndexRoute()} />

I would use...

<IndexRedirect to='landing' />

Refactoring your code:

<Route path="/" onEnter={this.verifyLang}>

  <Route path=":lang" onEnter={this.verifyLang}>

    <IndexRedirect to='landing' />

    <Route path="auth">
      <Route path="confirm-password" component={this.getIndexRoute()} />
      <Route path="confirm-code/code=:code&email=:email" component={this.getIndexRoute()}  />
      <Route path="confirm_email" component={this.getIndexRoute()}  />
    </Route>

    <Route path="landing" component={Landing} />
    <Route path="impress" component={Impress} />
  </Route>
</Route>
Julio Betta
  • 2,275
  • 1
  • 25
  • 25