首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从url vue中删除/#/

如何从url vue中删除/#/
EN

Stack Overflow用户
提问于 2021-10-18 20:15:35
回答 2查看 1.2K关注 0票数 2

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

代码语言:javascript
复制
http://localhost:8080/#/

http://localhost:8080/#/categorias

我该怎么移除它?

所以看起来像这样?

代码语言:javascript
复制
http://localhost:8080/categorias
http://localhost:8080/

这是我的js路由器

代码语言:javascript
复制
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

谢谢您的帮助,因为我还没能解决这个问题,如果有这样的网址,我会感到很不舒服。

EN

回答 2

Stack Overflow用户

发布于 2021-10-18 20:21:46

使用createWebHistory (HTML5模式)而不是createWebHashHistory (散列模式)

代码语言:javascript
复制
import { createRouter, createWebHistory } from 'vue-router'
...
const router = createRouter({
  history: createWebHistory(),
  routes
})
票数 5
EN

Stack Overflow用户

发布于 2021-10-19 02:27:17

vue

代码语言:javascript
复制
import VueRouter from 'vue-router'
const router = new VueRouter({
  routes,
  mode:'history'
})

nginx :当您在web服务(例如:linux)上部署它时,.you显示添加此配置

代码语言:javascript
复制
server {
        listen       80;
        server_name  localhost;
        server_name_in_redirect off;

        location / {
            root   /etc/nginx/html; // deploy html path
            index  index.html index.htm;
            if (-d $request_filename) {
                rewrite ^/(.*) /index.html break;
            }
            if (!-e $request_filename) {
                rewrite ^/(.*) /index.html break;
            }
     } 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69622067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档