The following error occurs when the VUE is changed from a static route to a dynamic route

The static route was loaded lazily. When we wrote the router to import(), it was loaded normally, but when we pulled the data from the API interface, we found that the above error was not reported.

export const importPath = (comUrl) => {  
  return () => import(`@${comUrl}.vue`)
}
Copy the code

Analyze the data returned by the background

/ const path = importPath(Component) console.log(path) path =. / const path = importPath(Component) console.log(path) path = @/views/process/report/index.vueCopy the code

This is how the error was reported, but I found the problem after reviewing the Webpack import documentation

Import The incoming address is looked up using the re

Please refer to the webpack import documentation

Modify the importPath method

export const importPath = (comUrl) => { const path = subObliqueLine(comUrl) return () => import(`@/${path}.vue`) } // Delete the left slash/export const subObliqueLine = (STR) => {if (STR === undefined) {return STR} return str.replace(/(^\/*)/g, '')}Copy the code

My Webpack version number