Skip to content
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

从数据库查到数据后, 动态加载路由, 报Cannot find module #1141

Closed
moxuanluo opened this issue Sep 28, 2018 · 7 comments
Closed

Comments

@moxuanluo
Copy link

大神您好,我 从后台数据库查寻数据生成路由表,菜单列表,权限都能出来,但是在路由异步加载的时报Cannot find module '@/views/layout/layout'
希望大神您能帮我看一下问题出在了哪里
我是将路径@/views/layout/layout 用varchar格式存入mysql 数据库 将数据查询到页面后,
我创建了变量来接受路由信息
let newRouter =[
{ path: data.path,
component: () => import(data.component),
name:data.name
}
]
变量创建完毕后,执行了
accessedRouters = filterAsyncRouter(nr, roles)
commit('SET_ROUTERS', accessedRouters)
成功生成addRouters

页面 可以 成功显示出 对应的菜单, 但是 点击菜单进行路由时,就会报Cannot find module ‘@/views/layout/layout ’ 这个错误,

我把上面的 newRouter 变量的 component 直接写成 () => import(‘@/views/layout/layout ’ ) 是不会报任何的错误,
想问一下 大神 () => import(data.component) 如何才能成功路由

@PanJiaChen
Copy link
Owner

#293

@lmasdata
Copy link

@moxuanluo 问题解决了么,
我用 () => import('@/views/path')这种方式加载接口返回的路由,点击后提示 Failed to mount component: template or render function not defined.

@wei1793786487
Copy link

请问下载这个问题解决了吗

@x1200085
Copy link

我同样遇到这个问题,久思未果,如果问题有结果请麻烦告知

@wei1793786487
Copy link

我同样遇到这个问题,久思未果,如果问题有结果请麻烦告知
我是这样解决的,本地缓存一份路由表。
image
image

@JamiLanister
Copy link

同遇到这个问题。。直接写就没问题

@x1200085
Copy link

x1200085 commented Jun 4, 2020

完美解决。
route.component = loadView(route.component)

export const loadView = (view) => { // 路由懒加载
return (resolve) => require([@/views/${view}], resolve)
}
解决方案来自:
https://gitee.com/y_project/RuoYi-Vue/blob/da5c1328beb06a4c785aa2791a2b9ca3bbeefaa6/ruoyi-ui/src/store/modules/permission.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants