【问题标题】:Hash in history mode router, breaks dynamic URL in Vue历史模式路由器中的哈希,破坏了 Vue 中的动态 URL
【发布时间】:2022-01-21 00:35:48
【问题描述】:

使用 Vue 2.6.14,Vue Router 设置为历史模式,包含标签“#”的 URL 会破坏动态路径。

const router = new VueRouter({
  base: `${process.env.VUE_APP_PUBLIC_PATH}`,
  mode: 'history',
  routes: [
    {
      path: '/document/:documentId(.*)',
      name: 'Document',
      component: Document,
      props: true
    },
    {
      path: '*',
      name: 'NotFound',
      component: NotFound
    }
  ]
});

以“/document/#1”结尾的 URL 作为“documentId”属性的空字符串返回。

【问题讨论】:

    标签: vue.js router history mode hashtag


    【解决方案1】:
    documentIdHashtagProof() { return this.documentId ? this.documentId : this.$route.hash; }
    

    问题是动态道具“documentId”返回空字符串,我已经通过使用读取哈希的计算属性解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2020-02-13
      • 2020-08-14
      • 2023-03-19
      • 2019-06-06
      • 2021-06-03
      • 2021-09-27
      • 2018-07-29
      • 2018-02-16
      • 2018-10-02
      相关资源
      最近更新 更多