inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue3 완벽 마스터: 기초부터 실전까지 - "실전편"

새로고침시 404 문제

1918

ChanYoung Kim

작성한 질문수 2

0

https://www.inflearn.com/questions/640711/url%EB%A1%9C-%EC%A7%81%EC%A0%91-%EC%A0%91%EA%B7%BC%EC%8B%9C-404-return-%EB%AC%B8%EC%A0%9C

위에 질문드린분과 완전 동일한 증상입니다. 다른점은 https://chanyoung-dev.github.io/ 는 이미 사용중이어서 https://chanyoung-dev.github.io/vuePost/ 도메인에 배포하기 위해 vite.config.js에서 base설정한 것(base: '/vuePost/')과 history: createWebHistory('/vuePost/') 있습니다.

https://chanyoung-dev.github.io/vuePost/ 에 접속하여 /posts라우트 영역에 들어가면 정상적으로 되지만 해당 페이지에서 새로고침을 한다든가 주소창에 직접 https://chanyoung-dev.github.io/vuePost/posts 로 들어가면 github 404페이지가 나타납니다. 로컬에서는 주소창에 http://localhost:5173/vuePost/posts 치면 정상적으로 접속됩니다.

github pages와 github action을 통해 배포해서 https://vitejs.dev/guide/static-deploy.html#github-pages 를 참고했는데도 안되네요 ㅜㅜ

 

아래는 제가 설정한 부분입니다

vite.config.js

import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  base: '/vuePost/',
});

route 부분

import { createRouter, createWebHistory } from 'vue-router';
import HomeView from '@/views/HomeView.vue';
import AboutView from '@/views/AboutView.vue';
import PostCreateView from '@/views/posts/PostCreateView.vue';
import PostDetailView from '@/views/posts/PostDetailView.vue';
import PostEditView from '@/views/posts/PostEditView.vue';
import PostListView from '@/views/posts/PostListView.vue';

const routes = [
  {
    path: '/',
    component: HomeView,
  },
  {
    path: '/about',
    component: AboutView,
  },
  {
    path: '/posts',
    component: PostListView,
    name: 'PostList',
  },
  {
    path: '/posts/create',
    component: PostCreateView,
    name: 'PostCreate',
  },
  {
    path: '/posts/:id',
    component: PostDetailView,
    name: 'PostDetail',
  },
  {
    path: '/posts/:id/edit',
    component: PostEditView,
    name: 'PostEdit',
  },
];

const router = createRouter({
  history: createWebHistory('/vuePost/'),
  routes: routes,
});

export default router;

 

git action

https://vitejs.dev/guide/static-deploy.html#github-pages 와 동일

# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
  # Runs on pushes targeting the default branch
  push:
    branches: ['master']

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
  contents: read
  pages: write
  id-token: write

# Allow one concurrent deployment
concurrency:
  group: 'pages'
  cancel-in-progress: true

jobs:
  # Single deploy job since we're just deploying
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 18
          cache: 'npm'
      - name: Install dependencies
        run: npm install
      - name: Build
        run: npm run build
      - name: Setup Pages
        uses: actions/configure-pages@v3
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v1
        with:
          # Upload dist repository
          path: './dist'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v1

git 주소: https://github.com/ChanYoung-dev/vuePost

하루죙일 삽질 뒤에 질문 남깁니다 감사합니다 

vue.js

답변 1

3

짐코딩

안녕하세요 :)

페이지 새로고침에 모든 URL(ex: /, /home, /about)에 대해 index.html 파일을 내려주어야 하는데요. 이렇게 하기위해서는 웹 서버에 설정이 필요합니다. 현재 Github Pages는 이러한 설정을 지원하지 않으며,

1

ChanYoung Kim

감사합니다 ~!

질문드립니다.

0

32

0

unplugin-vue-components 질문드립니다.

0

41

2

강의듣다가 헷갈려서 질문드립니다.

0

35

1

와 짐코딩님 강의 들으면서 느끼는게 많네요.

0

33

1

질문드립니다.

0

33

2

라우터 인스톨 후 실행안됨

1

50

2

코드 자동 포매팅 질문

0

71

2

필터 watchEffect 질문입니다.

0

52

1

json-server 오류가 다른게 뜨네요

0

114

1

미리보기가 안됩니당...

0

70

2

unplugin-vue-components

0

86

2

TypeError 질문

0

53

1

v-model="show" :show="show" 같이 사용?

1

58

1

hash 모드 배포의 필요성?

0

63

2

.eslintrc.cjs 가 없습니다

0

96

2

title,content값이 비어서 저장되는데 제가 혹시 어떤 부분을 잘못 작성했는지 ㅜㅜ 알고싶습니다.

0

98

3

_title_like: "", 문의드려요 해당 값을 설정하면 list가 아에 안나옵니다.

0

65

1

@click.prevent="params._page = pageNum"> 에 .value를 안쓰는 이유가 궁금합니다.

0

73

2

중첩된 컴포넌트 문제

0

76

2

교안에 있는 부분이 아닌가요?

0

109

2

useAxios Proxy(Object) RefImpl

0

114

1

axios timeout

0

334

3

강의와 상관은 없지만, 궁금한 점이 있어 질문드립니다.

0

124

2

컴포넌트 분리 부분에서 오류가 나요ㅠㅠ

0

170

2