Сделать так, чтобы роутер не выдавал 404 страницу Github Pages

Рейтинг: 0Ответов: 1Опубликовано: 22.05.2023

Моё приложение, написанное на vue находится на Github Pages. У меня есть роутер

import {createRouter, createWebHistory} from "vue-router";
import Index from "../components/screens/Index.vue";
import NoMeta from "../components/screens/NoMeta.vue";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {name: "index", path: "/", component: Index},
        {name: "noMeta", path: "/nometa", component: NoMeta}
    ],
})

export default router;

Но при попытке обратиться на страницу /nometa выдаёт ошибку 404. Что делать?

Ответы

▲ 0

Просто в качестве строкового аргумента для createWebHistory() добавьте название репозитория, например 'myrepo':

import {createRouter, createWebHistory} from "vue-router";
import Index from "../components/screens/Index.vue";
import NoMeta from "../components/screens/NoMeta.vue";

const router = createRouter({
    history: createWebHistory('/myrepo'),
    routes: [
        {name: "index", path: "/", component: Index},
        {name: "noMeta", path: "/nometa", component: NoMeta}
    ],
})

export default router;