How does vue routing make the 404 page jump to the outside site?

Viewed 45

A common configuration is this:

{path:'/*', name:'404', component:()=>import('@/views/404.vue')},

This will jump to a vue page, but now I want to jump to a public 404 page outside the site, how do I do it?

Tried this, doesn't work:

{path:'/*', redirect:'http://*.com/404.html'},

The current method is to enter 404.vue first, and then run window.location.href="http://...."

I want to ask the big guys, can you set it directly in the routing table?

2 Answers

Use this code in your router

{path:'*', name:'404', redirect:()=>{ window.location.href="some-url"}}

or

{path:'*', name:'404', component:()=> {window.location.href="some-url"}}

or if you want your component, instead of using redirect use your 404 vue component in your router

{path:'*', name:'404', component:()=>import('@/views/404.vue')}

Then in your 404.vue component in beforeCreate Lifecycle Hooks add this code

<script>
 export default {
  beforeCreate() {
    window.location.href = 'some_url'
  },
 
};
</script>

It seems impossible.

But you can write components directly in the route here.

{path:'/*', name:'404', component: function(){window.location.href="http://sf.gg"}}
Related