gpt4 book ai didi

Vue.js - 如何删除 hashbang #!从网址?

转载 作者:搜寻专家 更新时间:2023-10-30 22:07:13 26 4
gpt4 key购买 nike

如何从 url 中删除 hashbang #!

我在 vue 路由器文档 ( http://vuejs.github.io/vue-router/en/options.html ) 中找到了禁用 hashbang 的选项,但是这个选项删除了 #! 并只输入了 #

有什么办法可以得到干净的 url 吗?

例子:

不是:#!/home

但是:/home

谢谢!

最佳答案

Vue 3 中,您需要为 history 选项使用 createWebHistory

import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
history: createWebHashHistory(),
// ...
})

Vue 2 中,您需要将 mode 设置为 'history'

const router = new VueRouter({
mode: 'history',
// ...
})

不过,请确保您的服务器已配置为处理这些链接。 https://router.vuejs.org/guide/essentials/history-mode.html

关于Vue.js - 如何删除 hashbang #!从网址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34623833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com