Skip to content

query 변경 시 redirect 되는 문제 #633

Answered by woohm402
jm020827 asked this question in Q&A
Discussion options

You must be logged in to vote

https://v5.reactrouter.com/web/api/Switch

공식문서에 따르면 Switch 는 직계 child 중 첫 번째로 생성 가능한 친구만 살리고 나머지는 띄우지 않는 친구입니다.
올려주신 코드의 첫 번째 파트를 보면 아래와 같은 형식입니다. (줄번호는 그냥 설명 편의상 달았습니다)

1  <Switch>
2   <>
3     <Route />
    ...
29  </>
30 </Switch>

즉 Switch의 직계 child 중 첫 번째 녀석인 2~29번 줄이 모두 살게 됩니다. 즉 그 Switch는 아무 효과를 내지 못합니다.
아무튼, 그 효과로 인해 해당 코드는 Switch 없이 아래를 리턴한 것과 같은 효과를 냅니다.

              <Route path="/students" >
                <div className="App" key="students">
                   ...어쩌구
                </div>
              </Route>
              <Route path="/student/:id">
                <div className="App" key="student/id">
                  ...저쩌구
                </div>
              </Route…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@jm020827
Comment options

jm020827 Nov 5, 2021
Collaborator Author

@jm020827
Comment options

jm020827 Nov 5, 2021
Collaborator Author

@woohm402
Comment options

@jm020827
Comment options

jm020827 Nov 5, 2021
Collaborator Author

@jm020827
Comment options

jm020827 Nov 5, 2021
Collaborator Author

Answer selected by woohm402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
React React 관련 내용 question 질문으로 사용될 이슈
2 participants