-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare global { | ||
interface Window { | ||
navigateTo: (path: string) => void; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ | |
"official": "组件库", | ||
"community_wiki": "社区文档" | ||
} | ||
}, | ||
"navbar": { | ||
"home": "主页" | ||
} | ||
}, | ||
"text": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export const routerRootPathList = { home: '/', introduction: '/introduction', components: '/components', api: '/api', more: '/more' }; | ||
|
||
export const pathUtils = { | ||
/** | ||
* 处理路径 | ||
* @param {string} path 待处理路径 | ||
* @returns {string} | ||
*/ | ||
parsePath(path) { | ||
let parsedPath = path; | ||
if (parsedPath.startsWith('#')) { | ||
parsedPath = parsedPath.substring(1); | ||
} | ||
if (!parsedPath.startsWith('/')) { | ||
parsedPath = '/' + parsedPath; | ||
} | ||
return parsedPath; | ||
}, | ||
/** | ||
* 只按 routerRootPathList 来看,currentPath 是否找不到 | ||
* @param {string | null} currentPath | ||
* @returns {boolean} | ||
*/ | ||
isNotFound(currentPath) { | ||
if (currentPath === null) { | ||
return true; | ||
} | ||
let found = false; | ||
for (const key in routerRootPathList) { | ||
const path = routerRootPathList[key]; | ||
if (this.isSubPath(currentPath, path)) { | ||
found = true; | ||
break; | ||
} | ||
} | ||
return !found; | ||
}, | ||
/** | ||
* 比较 currentPath 是否为 parentPath 的子路径,或者二者相等 | ||
* 注意:parentPath 为根目录时始终返回 false | ||
* @param {string | null} currentPath | ||
* @param {string} parentPath | ||
* @returns {boolean} | ||
*/ | ||
isSubPath(currentPath, parentPath) { | ||
if (currentPath === null) { | ||
return false; | ||
} | ||
if (currentPath.startsWith(parentPath + '/') || currentPath === parentPath) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
}; |