From b493aa266dcf3bf5fddeaa2abad32f8bd103475e Mon Sep 17 00:00:00 2001 From: koooooo-7 <369491420@qq.com> Date: Tue, 10 Mar 2020 21:59:07 +0800 Subject: [PATCH 1/5] [fix #1046] fix cross-origin url cannot be redirected when "externalLinkTarget" is set to "_self" and "routerMode" is set to "history". --- docs/helpers.md | 6 ++++++ src/core/config.js | 1 + src/core/render/compiler/link.js | 11 +++++++++++ src/core/router/history/html5.js | 7 ++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/helpers.md b/docs/helpers.md index 83c59784a..4098679b5 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -65,6 +65,12 @@ You will get `link`html. Do not worry, you can still set ti [link](/demo ':disabled') ``` +## Cross-Origin link +Only when u set the `routerMode: 'history'` and `externalLinkTarget: '_self'` , you need add this configuration for those Cross-Origin links +```md +[example.com](https://example.com/ ':crossorgin') +``` + ## Github Task Lists ```md diff --git a/src/core/config.js b/src/core/config.js index c35179059..f3413a778 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -32,6 +32,7 @@ export default function() { externalLinkRel: 'noopener', routerMode: 'hash', noCompileLinks: [], + crossOriginLinks: [], relativePath: false, topMargin: 0, }, diff --git a/src/core/render/compiler/link.js b/src/core/render/compiler/link.js index faf2e4f7c..71246bb15 100644 --- a/src/core/render/compiler/link.js +++ b/src/core/render/compiler/link.js @@ -30,6 +30,17 @@ export const linkCompiler = ({ renderer, router, linkTarget, compilerClass }) => attrs.push(`target="${config.target}"`); } + // special case to check crossorigin urls + if ( + config.crossorgin && + linkTarget === '_self' && + compilerClass.config.routerMode === 'history' + ) { + if (compilerClass.config.crossOriginLinks.indexOf(href) === -1) { + compilerClass.config.crossOriginLinks.push(href); + } + } + if (config.disabled) { attrs.push('disabled'); href = 'javascript:void(0)'; diff --git a/src/core/router/history/html5.js b/src/core/router/history/html5.js index d0b2a9a31..28fa2ea27 100644 --- a/src/core/router/history/html5.js +++ b/src/core/router/history/html5.js @@ -27,7 +27,12 @@ export class HTML5History extends History { if (el.tagName === 'A' && !/_blank/.test(el.target)) { e.preventDefault(); const url = el.href; - window.history.pushState({ key: url }, '', url); + // solve history.pushState cross-origin issue + if (this.config.crossOriginLinks.indexOf(url) !== -1) { + window.open(url, '_self'); + } else { + window.history.pushState({ key: url }, '', url); + } cb({ event: e, source: 'navigate' }); } }); From da047856da24e84c98a28997e4f3c30537399b43 Mon Sep 17 00:00:00 2001 From: koooooo-7 <369491420@qq.com> Date: Sun, 15 Mar 2020 18:01:08 +0800 Subject: [PATCH 2/5] [code format] code format. From 4f25e954d04e9141b1068be3aa70c1893aa1264e Mon Sep 17 00:00:00 2001 From: Koy <369491420@qq.com> Date: Thu, 14 May 2020 23:23:28 +0800 Subject: [PATCH 3/5] update docs --- docs/helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/helpers.md b/docs/helpers.md index 4098679b5..2dc9f5b2c 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -66,7 +66,7 @@ You will get `link`html. Do not worry, you can still set ti ``` ## Cross-Origin link -Only when u set the `routerMode: 'history'` and `externalLinkTarget: '_self'` , you need add this configuration for those Cross-Origin links +Only when you set the `routerMode: 'history'` and `externalLinkTarget: '_self'` , you need add this configuration for those Cross-Origin links ```md [example.com](https://example.com/ ':crossorgin') ``` From 833a72f03d0c76ea159e4b24bbe3566e6996ba9e Mon Sep 17 00:00:00 2001 From: Koy <369491420@qq.com> Date: Thu, 14 May 2020 23:32:06 +0800 Subject: [PATCH 4/5] docs refine. --- docs/helpers.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/helpers.md b/docs/helpers.md index 2dc9f5b2c..922eab548 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -66,7 +66,9 @@ You will get `link`html. Do not worry, you can still set ti ``` ## Cross-Origin link -Only when you set the `routerMode: 'history'` and `externalLinkTarget: '_self'` , you need add this configuration for those Cross-Origin links + +Only when you set the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need add this configuration for those Cross-Origin links. + ```md [example.com](https://example.com/ ':crossorgin') ``` From c6d7f5acc79aa06c85774d0cc2466fd7c378a343 Mon Sep 17 00:00:00 2001 From: Koy <369491420@qq.com> Date: Thu, 14 May 2020 23:46:49 +0800 Subject: [PATCH 5/5] fix(core): cross-orgin link work incorrect (#1046) Fix cross-origin url cannot be redirected when "externalLinkTarget" is set to "_self" and "routerMode" is set to "history". Add new configuration for those cases and completed docs. Fixes #1046 PR Close #1062 --- docs/helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/helpers.md b/docs/helpers.md index 922eab548..9cb511f96 100644 --- a/docs/helpers.md +++ b/docs/helpers.md @@ -67,7 +67,7 @@ You will get `link`html. Do not worry, you can still set ti ## Cross-Origin link -Only when you set the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need add this configuration for those Cross-Origin links. +Only when you both set the `routerMode: 'history'` and `externalLinkTarget: '_self'`, you need add this configuration for those Cross-Origin links. ```md [example.com](https://example.com/ ':crossorgin')