Rakish Frisky
Rakish Frisky

Reputation: 675

How to make *.vue file in nuxt

I know that my question seems weird but I'm seriously lost in here, I read some article to redirect all not-found page in nuxt to / or home or index but in this tutorial tell me to make page/*.vue. First of all I know that * this asterisk symbol means all but whenever I try to make *.vue file it always give me not valid files in Visual Studio Code. can someone help me to solve this?

this is the article that I read redirect-404-not-found-in-nuxt-js I already try the code in this article and it works and redirect my 404.vue page to home but it is not the solution I seek since it means I must declare all possible file for not found and of course it is not a good solution.

this is the 404.vue code that I want to use in *.vue:

<!-- pages/*.vue -->
<script>
export default {
  asyncData ({ redirect }) {
    return redirect('/')
  }
}
</script>

Upvotes: 1

Views: 247

Answers (1)

ziggybrew
ziggybrew

Reputation: 91

*.vue is not a valid file name. I didn't use Nuxt when creating my 404 page - I just used regular old Vue.

First I created a component and called mine notFoundComponent.vue (can call yours whatever) and created a View as well and called that notFoundView.vue. I then coded those pages to display the 404 error how I wanted.

On my router.js page, I added the following to the end of the routes and it works as intended:

{ name: 'notFoundView', path: '*', component: notFoundView }

Upvotes: 1

Related Questions