how to create a 404 component in vuejs using vue-router

后端 未结 5 1075
慢半拍i
慢半拍i 2020-12-13 13:13

I\'m new to vuejs and I\'m working on my first project with vue. I\'m just wondering how I will route to my 404.vue component when the requested url is not found.

An

5条回答
  •  温柔的废话
    2020-12-13 13:29

    For what I do is I give a class of http-found to the parent div all my component and I the mounted hook of the App.vue I check using jQuery or Javascript if there is any element with the class of http-found if not I redirect to my 404 page.

    App.vue

    mounted(){
       if(!$('.http-found')){
         this.$router.push('/404')
       }
    }
    

提交回复
热议问题