gpt4 book ai didi

vue.js - 如何从 url vue 中删除/#/

转载 作者:行者123 更新时间:2023-12-05 09:30:25 28 4
gpt4 key购买 nike

我在 vue 中工作,当查看页面时,链接显示如下:

http://localhost:8080/#/

http://localhost:8080/#/categorias

如何删除它?

所以它看起来像这样?

http://localhost:8080/categorias
http://localhost:8080/

this is my js router

import { createRouter, createWebHashHistory } from 'vue-router'
//import Home from '../views/Home.vue'
import Inicio from '../components/Inicio.vue'
const routes = [
{
path: '/',
name: 'inicio',
component: Inicio
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
},
{
path: '/categorias',
name: 'Categorias',

component: () => import(/* webpackChunkName: "about" */ '../components/Categorias.vue')
},
{
path: '/login',
name: 'Login',

component: () => import(/* webpackChunkName: "about" */ '../components/Login.vue')
}

]


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

export default router

感谢您提供的任何帮助,因为我无法解决它,并且以这种方式使用该 url 很不舒服 :D

最佳答案

使用 createWebHistory ( HTML5 Mode ) 而不是 createWebHashHistory ( Hash Mode )

import { createRouter, createWebHistory } from 'vue-router'
...
const router = createRouter({
history: createWebHistory(),
routes
})

关于vue.js - 如何从 url vue 中删除/#/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69622067/

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