页面刷新时的 Vue 路由器得到 404 [英] Vue router on page refresh gets 404

查看:33
本文介绍了页面刷新时的 Vue 路由器得到 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在历史模式下使用 Vue 路由器.在按钮上单击当前页面,我将其路由到下一页.在我重新加载的第二页上,我收到 404.有没有办法在 Vue 中处理这个问题并将其重定向到主页.

I am using Vue router with history mode. On button click on the current page I route it to next page. On second page when i reload i get a 404. Is there a way to handle this in Vue and redirect it to home page.

export default new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      name: "first",
      component: First
    },
    {
      path: "/abc",
      name: "abc",
      component: Second,
      props: true
    },

推荐答案

你可以使用hash模式嵌套历史模式来解决你路由器上的问题

you can use hash mode inested of history mode to resolve the problem on your router

let router = new Router({
    mode: "hash",
  routes: [
    {
    //and the urls with path on here ...

这篇关于页面刷新时的 Vue 路由器得到 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆