Skip to content

Commit fe0bcc7

Browse files
committed
路由优化:如果非noscheme形式的链接,如果协议不是http(s),那么路由不会处理这类链接
1 parent a2f0a90 commit fe0bcc7

5 files changed

Lines changed: 19 additions & 21 deletions

File tree

‎dist/js/sm-extend.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/js/sm.js‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7374,19 +7374,14 @@ Device/OS Detection
73747374
var linkEle = $link.get(0);
73757375
var linkHref = linkEle.getAttribute('href');
73767376

7377-
// 如果是一下协议,那么不使用路由功能
7378-
var protoBlackList = [
7379-
'tel:',
7380-
'javascript:', // jshint ignore:line
7381-
'mailto:'
7377+
var protoWhiteList = [
7378+
'http',
7379+
'https'
73827380
];
73837381

7384-
if (linkHref) {
7385-
for (var j = protoBlackList.length - 1; j >= 0; j--) {
7386-
if (linkHref.indexOf(protoBlackList[j]) === 0) {
7387-
return true;
7388-
}
7389-
}
7382+
//如果非noscheme形式的链接,且协议不是http(s),那么路由不会处理这类链接
7383+
if (/^(\w+):/.test(linkHref) && protoWhiteList.indexOf(RegExp.$1) < 0) {
7384+
return true;
73907385
}
73917386

73927387
//noinspection RedundantIfStatementJS

‎dist/js/sm.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/demos/routers/index.html‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ <h1 class="title">路由 Demo 页面 A</h1>
3030
</div>
3131

3232
<div class="content-block-title">默认下面这些协议的链接不使用路由功能</div>
33-
<div class="content-padded disable-router">
33+
<div class="content-padded">
3434
<ul>
3535
<li>
3636
<a href="tel:10086">电话 tel:</a>
3737
</li>
38+
<li>
39+
<a href="mailto:xx@yy.com">mailto:xx@yy.com;</a>
40+
</li>
3841
<li>
3942
<a href="javascript:;">javascript:;</a>
4043
</li>

‎js/router.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,14 @@
861861
var linkHref = linkEle.getAttribute('href');
862862

863863
var protoWhiteList = [
864-
+ 'http',
865-
+ 'https'
866-
];
867-
868-
if(/^(\w+):\/?./.test(linkHref)){
864+
'http',
865+
'https'
866+
];
869867

870-
return !~protoWhiteList.indexOf(RegExp.$1);
871-
}
868+
//如果非noscheme形式的链接,且协议不是http(s),那么路由不会处理这类链接
869+
if (/^(\w+):/.test(linkHref) && protoWhiteList.indexOf(RegExp.$1) < 0) {
870+
return true;
871+
}
872872

873873
//noinspection RedundantIfStatementJS
874874
if (linkEle.hasAttribute('external')) {

0 commit comments

Comments
 (0)