-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[router] router中会遇到router为undefined情况导致route.path报错 #735
Labels
Duplicate
This issue or pull request already exists
Comments
👋 @xiaotuanyu120,感谢给 TDesign 提出了 issue。 |
|
请通过 |
|
按照前面的做法,把route提前检查了下是否为undefined之后,有了新的warn [Vue warn]: inject() can only be used inside setup() or functional components. 网查了下,好像是因为useRoute()这个函数有inject方法,这个必须要放到setup()中去。 所以我做了如下改动:
export const getActive = (route: RouteLocationNormalizedLoaded | null | undefined, maxLevel: number = 3): string => {
if (!route || !route.path) {
return '';
}
return route.path
.split('/')
.filter((_item: string, index: number) => index <= maxLevel && index > 0)
.map((item: string) => `/${item}`)
.join('');
};
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
...getActive(route)... 这样我本地环境就不会再报错了,麻烦看下这样是否合理,若不合理,正确的解决方案应该是怎样的 |
重复 #698 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tdesign-vue-next-starter 版本
0.6.1
重现链接
No response
重现步骤
macos: 13.0.1
node: v22.4.1
nvm: 10.8.1
按照指引,通过如下选择初始化项目
然后npm run dev访问页面,切换左侧栏中的任意其他项目
期望结果
期望是正常切换到其他左侧栏
实际结果
实际会卡住,然后控制台报错:
框架版本
vue(3.2.31)
浏览器版本
chrome(126.0.6478.127)
系统版本
macos(13.0.1)
Node版本
22.4.1
补充说明
我本地通过将源代码
src/router/index.ts
中的修改为
之后,可以正常访问,但是我不清楚这个route对象为undefined是否符合预期
The text was updated successfully, but these errors were encountered: