Skip to content

Commit b7c338a

Browse files
committed
fix 获取URL中版本号错误问题
1 parent 45b69a3 commit b7c338a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

examples/js/common.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ $(document).ready(function () {
4848
$('#version').html(versionText);
4949
}
5050

51+
function getVersion() {
52+
var pathname = window.location.pathname.replace("/en/", "/");
53+
var match = pathname.match(/^\/(dev|example|(?:\d+\.)+\d)\/.*/);//匹配版本:dev|web|9.0.0
54+
return match && match[1] !== "example" ? match[1] : null;
55+
}
56+
5157

5258
//重置当前版本链接,不带版本号
5359
function resetCurrentVersionLink() {
@@ -88,18 +94,12 @@ $(document).ready(function () {
8894
var pathname = window.location.pathname.replace("/en/", "/");
8995
var href = window.location.origin + pathname;
9096
if (lang === "en-US") {
91-
var match = pathname.match(/([^\/]*\/){2}([^\/]*)/);
92-
if (match && match[2]) {
93-
var versionReg = match[2].match(/dev|^(.*)\.(.*)$/);//匹配版本:dev/9.0.0
94-
if (versionReg) {
95-
// href = window.location.origin + pathname.replace(/([^\/]*\/){1}([^\/]*)/, '$1$2/en');
96-
href = window.location.origin + pathname.replace(/([^\/]*\/){2}([^\/]*)/, '/$1$2/en');
97-
}else if(window.isLocal) {
98-
href = window.location.origin + pathname.replace(/(([^\/]*\/){3})([^\/]*)/,'$1$3/en');
99-
}
100-
} else if(window.isLocal) {
101-
href = window.location.origin + pathname.replace(/(([^\/]*\/){3})([^\/]*)/,'$1$3/en')
102-
}else {
97+
if (getVersion()) {
98+
// href = window.location.origin + pathname.replace(/([^\/]*\/){1}([^\/]*)/, '$1$2/en');
99+
href = window.location.origin + pathname.replace(/([^\/]*\/){2}([^\/]*)/, '/$1$2/en');
100+
} else if (window.isLocal) {
101+
href = window.location.origin + pathname.replace(/(([^\/]*\/){3})([^\/]*)/, '$1$3/en')
102+
} else {
103103
href = window.location.origin + pathname.replace(/([^\/]*\/){1}([^\/]*)/, '/en/$2');
104104
//href = window.location.origin + pathname.replace(/([^\/]*\/){1}([^\/]*)/, '/$2/en');
105105
}

0 commit comments

Comments
 (0)