멍
NavigationDuplicated Navigating to current location 본문
vue-router 중복 path 접근 시 발생하는 에러이다.
js해결법이나 여러가지 해결법들도 있었는데, typescript 기반으로 개발하다보니, 문법체크에서
넘어가질 않았고,
VueRouter.prototype.push 가 call을 할때 void를 뱉어내서
Property 'catch' does not exist on type 'void'. 라는 에러를 자꾸 뱉어냈는데,
좀더 검색해보니 stackoverflow에서 좋은 예시가 있어 가져왔다.
NavigationDuplicated Navigating to current location ("/search") is not allowed
When I want to do a search multiple times it shows me the NavigationDuplicated error. My search is in the navbar and the way I have configured the search is to take the value using a model and then...
stackoverflow.com
const superPush = VueRouter.prototype.push
VueRouter.prototype.push = async function push(loc:RawLocation):Promise<Route> {
try {
return await superPush.bind(this)(loc)
} catch (e) {
if (e?.name === 'NavigationDuplicated') {
console.warn(e)
return e
} else {
throw e
}
}
}