nuxtjs项目空白路由强跳到首页 北梦木兮

1.根目录下新建middleware文件夹并新建文件unknownRoute.js,代码如下

/**
 *   未知路由重定向 到首页
 */
export default ({store, route, redirect}) => {
    if(!route.matched.length){
        redirect('/')
    }
}

  


2.根目录下配置文件nuxt.config.js,写入配置代码

export default {
   router: {
    middleware: 'unknownRoute'
  }
}

  

原文地址:https://www.cnblogs.com/shimeng123/p/15788744.html