Home > other >  How to remove /#/ from the url vue
How to remove /#/ from the url vue

Time:10-19

I'm working in vue and when viewing the pages the link appears as follows:

http://localhost:8080/#/

http://localhost:8080/#/categorias

How do I remove it?

so that it looks like this ?

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

I appreciate any help thank you, as I have not been able to solve it and it is uncomfortable to have that url in that way :D

CodePudding user response:

Use createWebHistory (HTML5 Mode) instead of createWebHashHistory (Hash Mode)

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

CodePudding user response:

vue

import VueRouter from 'vue-router'
const router = new VueRouter({
  routes,
  mode:'history'
})

nginx : when you deploy it on the web service(eg: linux).you show add this config

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;
            }
     } 
  • Related