there is a requirement, that is, according to the menus, given by the background, it is dynamically processed and loaded into the route, but because the menu can be added at any time, if you do not notify the front end to add the menu, you also need to display the menu, but the corresponding component does not exist. If not, how can you judge and load the 404 page. The
code is as follows:
component: _import(item.name.replace(/\./g,"/")) ? _import(item.name.replace(/\./g,"/")) : _import("errorPage/404"),
but if the import is not found, it will directly report an error and will not execute the following.
before using the following methods to test
function matchVueFiles(name){
const context = require.context("@/views",true,/\.vue$/);
const keys = context.keys();
return keys.indexOf(name);
}
but this method is not available online because there are no folders online. Therefore, this method is not good either. I ask all the great gods to provide ideas and solutions.