반응형
Vue2는 위치가 있는 외부 URL로 이동한다.href
나는 라우터.go, 라우터를 사용하여 'www.mytargeturl.org'으로 가려고 했다.push, router.user 및 window.location.href 내 vuejs 앱을 리디렉션하는 것은 좋지만 나는 항상 myVueapp.com/www.mytargeturl.org을 얻는다. 내 경로:
routes:[
{path: '/', component: App,
children:[
{
path: 'detail',
component: ItemDetail,
props: true
},
{
path: 'search',
component: Middle
}
]
},
{
path: '/test', component: Test
},
{ path: '/a', redirect: 'www.mytargeturl.org' } // also tried this but didnt work
]
다른 논평에서 사람들과 일치했다.이미 해결된 문제를 해결하는 것이 부에의 철학은 아니다.저도 마찬가지에요.그냥 평범한 것을 써라.a
가능하면 링크에 태그를 추가하십시오.라우터를 통과해야 하는 경우, 탐색 가드를 사용하십시오.
{
path: '/redirect',
beforeEnter(to, from, next) {
// Put the full page URL including the protocol http(s) below
window.location.replace("https://example.com")
}
}
해결책을 찾았다.내 목표 URL에 http를 추가하면 모든 것이 잘 된다!이것처럼.window.location = 'http://mytargeturl.org"
이것은 단지 vue만이 아닌 보편적인 javascript 진실인 것 같다.
이 경우에는 내비게이션 가드를 사용할 필요가 없으며, 경로 구성에서 바로 동적 리디렉션을 사용할 수 있도록 클리너
routes:[
{
path: '/redirect-example',
redirect: (to: Route) => {
window.location.href = 'http://example.com'
return '/redirecting' // not important since redirecting
}
}
]
경로에서 리디렉션 URL을 사용하여 메타 속성을 설정하십시오.
{
name: "Shop",
path: "/shop",
component: {},
meta: { RedirectExternalUrl: "https://mystore.com" },
},
그리고 라우터 가드 기능을 설정하여 작업 수행:
router.beforeEach(async (to, from, next) => {
// External redirect
if (to.matched.some((record) => record.meta.RedirectExternalUrl)) {
const url: string = to.meta.RedirectExternalUrl as string;
window.location.replace(url);
return;
}
next();
});
참조URL: https://stackoverflow.com/questions/44595929/vue2-navigate-to-external-url-with-location-href
반응형
'Programing' 카테고리의 다른 글
Java Collection( 술어 기반)을 필터링하는 방법? (0) | 2022.04.27 |
---|---|
GNU가 다른 컴파일러를 사용하도록 설정 (0) | 2022.04.27 |
구성 요소를 동적으로 생성하고 vuej에서 프로그래밍 방식으로 값을 반환하는 방법 (0) | 2022.04.27 |
Vue-Test-Utils 알 수 없는 사용자 지정 요소: (0) | 2022.04.27 |
ncurs 없이 C/C+++에서 vim, htop, ...와 같은 "실제" 대화형 터미널 프로그램 작성 (0) | 2022.04.27 |