⚠️ This lesson is retired and might contain outdated information.

Catch All Undefined Paths with a Wildcard Route in Vue

Laurie Barth
InstructorLaurie Barth
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 months ago

We can use the "*" symbol to catch all matching paths. However, there are ways to do this that will override other paths. We want to avoid those.

Instructor: [00:01] We'll start by importing a new component called PageNotFound. This will act as a stand-in for our 404 page or similar.

[00:13] We're going to create a new route record. We'll set the component to PageNotFound, but the path will be /*. Star is a wildcard value that will match everything it hits.

[00:33] If we navigate to test, which is a URL we haven't defined, we'll end up on PageNotFound. If we move this route record up in our array, ahead of the Egghead path, and we try and navigate to test, we'll see what we want to see.

[00:55] If we navigate to Egghead, we find that it's overwritten because /* is hitting the path. What we want to do is remove the / and keep just *, which will allow us to hit other URLs that are also matching but still act as that wildcard catch-all.

[01:16] Alternatively, we can set our path to PageNotFound and alias that path to *. This allows us to do what we did before but also access PageNotFound directly through a URL if we were to want to navigate to it from another component.

[01:38] As we see, we can still hit Egghead without overwriting it.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today