基于哈希的路由器导航到不存在的URL会在哈希之前保存提供的路径名

时间:2019-04-11 16:46:41

标签: vue.js vue-router

当前导航到任何不存在的URL,例如:
localhost:3000/abc/cba

将使用以下URL加载主页:
localhost:3000/abc/cba#/

应用程序内部的进一步导航将继续,添加不存在的路径,例如: localhost:3000/abc/cba#/thisPathExist

我当前的路由器配置基本上是开箱即用的

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import(/* webpackChunkName: 'helper' */ './home.route.vue')
    },
    {
      path: '/thisPathExist',
      name: 'thisPathExist',
      component: () => import(/* webpackChunkName: 'thisPathExist' */ './thisPathExist.vue')
    },
  ]
})

我可以想象任何人都可以收听hashchange,然后通过删除#之前的URL剩余部分来“标准化” URL,但是我想知道是否还有另一种方式,甚至是{{ 1}}处理此类情况

0 个答案:

没有答案