본문 바로가기
영화 검색 사이트

[영화 검색 사이트] Vue Router 404 Page Not Found

by mikrw 2023. 2. 11.

https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route

 

Dynamic Route Matching with Params | Vue Router

Dynamic Route Matching with Params Very often we will need to map routes with the given pattern to the same component. For example we may have a User component which should be rendered for all users but with different user IDs. In Vue Router we can use a d

router.vuejs.org

 

 

index.js

import { createRouter, createWebHashHistory } from 'vue-router'
import Home from './Home'
import Movie from './Movie'
import About from './About'
import NotFound from './NotFound'

export default createRouter({
  // Hash, History
  // https://google.com/#/search
  history: createWebHashHistory(),
  // pages
  routes: [
    {
      path: '/',
      component: Home
    },
    {
      path: '/movie/:id',
      component: Movie
    },
    {
      path: '/about',
      component: About
    },
    {
      path: '/:notFound(.*)',
      component: NotFound
    }
  ]
})

 

 

NotFound.vue

<template>
  <div class="not-found">
    <div class="status">
      404
    </div>
    <div class="message">
      Page Not Found!
    </div>
  </div>
</template>

<style lang="scss" scoped>
  @import '~/scss/main';
  
  .not-found {
    line-height: 1.2;
    text-align: center;
    font-family: "Oswald", sans-serif;
    padding: 80px 20px;
    .status {
      font-size: 160px;
      color: $primary;
    }
    .message {
      font-size: 50px;
    }
  }
</style>