【问题标题】:[Vite - Vue 3]Page not found when reload page on Github[Vite - Vue 3]在 Github 上重新加载页面时找不到页面
【发布时间】:2021-11-28 15:53:15
【问题描述】:

当我点击 router-link 重定向到另一个页面时,它加载成功。

但是重新加载后,页面没有找到。

我使用 Vite 2.6、Vue 3.2 和 Vue Router 4.0。

在本地,它仍然可以正常工作,只是在我的 github.io 上失败。

vite.config.js

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

export default defineConfig({
    base: 'study',
    plugins: [vue()],
    build: {
        sourcemap: false,
    },
});

routes.js

import { createRouter, createWebHistory } from 'vue-router';
import Home from './views/Home.vue';
const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home,
    }
];
export default function () {
    return createRouter({
        history: createWebHistory('/study'),
        routes,
    });
}

main.js

import { createApp } from 'vue';
import App from './App.vue';
import createRouter from './router/routes';

const router = createRouter();
const app = createApp(App);
app.use(router);
app.mount('#app');

谢谢

【问题讨论】:

  • 可以分享index.html的代码吗?

标签: github vue-router vuejs3 vite


【解决方案1】:

您最好使用 apache 或 nginx 来托管您的文件 在 /dist 文件夹中创建一个文件并命名为 It .htaccess 然后将这些行放入其中。提到here

对于 Apache

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

然后将所有文件从dist复制到apache主文件夹中的hdocs

【讨论】:

    猜你喜欢
    • 2020-03-01
    • 2016-08-01
    • 2018-07-04
    • 1970-01-01
    • 2017-10-20
    • 2018-12-03
    • 2021-07-20
    • 1970-01-01
    • 2021-07-18
    相关资源
    最近更新 更多