How can i return 404 error without change url in Vue? How can i return 404 error without change url in Vue? vue.js vue.js

How can i return 404 error without change url in Vue?


Routers are designed to do exactly what you are wanting them to not do. If you want to display some content on any route in your application, I would recommend creating a new component and maybe firing off an event to show whatever content you want.

Personally, I would think re-routing would be the way to go because this will allow the user to hit the back button in the browser to get back to where they came from, but I guess that all depends on your specific use case here.


I'm still using vue router3 and works for me without changing the url.for axios.

beforeRouteEnter(to,from,next) { axios .get(`http://localhost:5000/api/product/${to.params.id}`) .then((res) => {    next((vm) => {      vm.product = res.data;      next();    });  })  .catch((error) => {           next({ name: 'notFound', params: [to.path]});          });}