浏览代码

fix(utils): 处理未找到lastPage时的currRoute返回

当getLastPage返回undefined时,currRoute现在会返回包含空path和空query的默认对象,避免潜在的运行时错误
feige996 8 月之前
父节点
当前提交
83e08353eb
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      src/utils/index.ts

+ 6 - 0
src/utils/index.ts

@@ -16,6 +16,12 @@ export function getLastPage() {
  */
 export function currRoute() {
   const lastPage = getLastPage()
+  if (!lastPage) {
+    return {
+      path: '',
+      query: {},
+    }
+  }
   const currRoute = (lastPage as any).$page
   // console.log('lastPage.$page:', currRoute)
   // console.log('lastPage.$page.fullpath:', currRoute.fullPath)