0
我剛開始使用的WebPack,我使用的是動態頁面加載反應的路由器,並且要動態導入我的文件,但得到的的WebPack這樣的警告:weback 2未能與反應路由器動態路徑導入文件
警告在./apps/pages/routes.js 35:6-44臨界依賴性:一個依賴的請求是一個表達式
這裏是我的代碼的示例:
const routes = {
component: App,
childRoutes: [
{
path: '/',
getComponent (location, cb) {
System.import('./Home')
.then(loadRoute(cb))
.catch(errorLoading)
}
},
{
path: 'about',
getComponent (location, cb) {
System.import('./About')
.then(loadRoute(cb))
.catch(errorLoading)
}
}
]
}
這工作得很好,但是當我想用這樣的變量,使其:
const routersPaths = [
{path: '/', filePath: './Home'},
{path: 'about', filePath: './About'}
]
const childRoutes = routersPaths.map(childRoute => {
return {
path: childRoute.path,
getComponent (location, cb) {
System.import(childRoute.filePath)
.then(loadRoute(cb))
.catch(errorLoading)
}
}
})
const routes = {
component: App,
childRoutes: childRoutes
}
失敗。我想知道有沒有辦法做到這一點?
謝謝你的回答。是的,我知道串聯字符串,但這不是我想要的。所以沒有辦法動態導入組件? – Gayane
不,沒有。 –