I would like to ask vue in the dynamic import to load the page, can you judge in advance whether the page exists, if not, then introduce 404component.

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
clipboard.png
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.

Jun.09,2021

provides a way of thinking
create a configuration file to configure existing routing components. Determine whether the item.name exists before import and then decide which one to load.

//config.js
export default {components:['a', 'b']}

you can wrap a layer of pseudo code on the outside of the dynamic component. It is possible to judge that the logic is not like this, the train of thought is like this

new Vue({
  // ...
  components: {
    'my-component': () => {
        return new Promise((resove, reject) => {
            var RemoteComponent = import('./my-async-component')
            var Component404 = import('./my-async-404-component')
            RemoteComponent.then(res => {
                resove(res)
            })
            
            RemoteComponent.catch(e => {
                Component404.then(res => {
                    resove(res)
                })
            })
        })
        
    }
  }
})
Menu