Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
How to use a 404 component in VUE3 single page app

I have the following structure of the code:

router.js:

  import { createRouter, createWebHistory } from 'vue-router';

  const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'App',
      component: () => import('../../src/App.vue'),
    },
    {
      path: '/:pathMatch(.*)',
      name: 'ErrorView',
      component: () => import('../components/Error.vue'),
  }
  ],
});

export default router;

App.vue

<template>
  <Land />
  <LeftNavbar />
  <Navbar />
  <Experience />
  <TechnologiesCarousel />
  <Projects />
  <Copyright />
  <BackToTop />
</template>

When I'm pressing in the URL bar: http://localhost:3000. The app is rendering properly which is fine, but when I'm trying to write a wrong URL, for eg: http://localhost:3000/abcf/ || http://localhost:3000/dsafbdmhgfjweghjfw to be redirected to the 404 page, I'm not redirected, the page still rendering the App.vue component.

Does anyone have any idea why the 404 page isn't rendered?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try like following /:pathMatch(.*)*:

{
  path: "/:pathMatch(.*)*",
  name: 'ErrorView',
  component: () => import('../components/Error.vue'),
},

and in App.vue place <router-view /> and move components to other view.

about 4 years ago · Juan Pablo Isaza Report

0

I assume you are using Vue 3.

In your router file you need to change the path to this:

  {
      path: '/:pathMatch(.*)*',
      name: 'ErrorView',
      component: () => import('../components/Error.vue'),
  }

For Vue 2 the path can be: path:'*'


From Vue 2 -> 3 migration some more info for those they want to know what has changed:

Essentially, you should be able to replace the '' path with '/:pathMatch(.)*' and be good to go!

Reason: Vue Router doesn't use path-to-regexp anymore, instead it implements its own parsing system that allows route ranking and enables dynamic routing. Since we usually add one single catch-all route per project, there is no big benefit in supporting a special syntax for *.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!