2017-06-06 8 views
0

で「/」から私はhttp://localhost:3000/account/signInにリダイレクトhttp://localhost:3000/account/signUpに行くときのセットアップは、「/アカウント」を「/アカウント/サインイン」リダイレクトリアクト-ルータ

<Layout> 
    <Switch> 
     <Redirect from="/account" to="/account/signIn" /> 
     <Route path="/account/signIn" component={() => <div>signIn</div>} /> 
     <Route path="/account/signUp" component={() => <div>signUp</div>} /> 
    </Switch> 
    </Layout> 

からリダイレクトしようとしています。 この問題は、このように固定されている:

<Layout> 
    <Route exact path="/account" render={() => <Redirect to="/account/signIn" />} /> 
    <Route path="/account/signIn" component={() => <div>signIn</div>} /> 
    <Route path="/account/signUp" component={() => <div>signUp</div>} /> 
    </Layout> 

しかし、私は疑問を持っているので、これはバグや正常な動作があり、それが最善の方法ではないと思いますか?

答えて

2

from<Redirect>は、デフォルトで緩やかに一致します。あなたが持っているので、/ account/signInと/ account/signUpパスを含む/ accountで始まるものと一致します。

スイッチの内部では、実際には子どもの小道具を直接読み取っており、コンポーネントの種類を区別しません。したがって、you can use exact and strictはあなたがルート上にできるようです。

したがって、これはあなたのために働く必要があります。

<Layout> 
    <Switch> 
    <Redirect exact from="/account" to="/account/signIn" /> 
    <Route path="/account/signIn" component={() => <div>signIn</div>} /> 
    <Route path="/account/signUp" component={() => <div>signUp</div>} /> 
    </Switch> 
</Layout>