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)
                })
            })
        })
        
    }
  }
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d95c-2c399.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d95c-2c399.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?