Bastian
Bastian

Reputation: 1

Vue.JS's router has "#" even with history mode enabled

I tried to remove # in URL of my VueJS webapp, but even with

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

# still appear. I'm pretty sure it's due to the createWebHashHistory function, but I can't remove it, or else, UI doesn't display.

So i tried another thing :

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

but ui doesn't even display here.

The Vue.JS's official documentation doesn't help me on that point, could anyone help me there ?

Upvotes: 0

Views: 3558

Answers (2)

Jevon Mozart CB
Jevon Mozart CB

Reputation: 13

This is my index.js

import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import About from "../views/About.vue";

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/about",
    name: "About",
    component: About,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;

Upvotes: 1

Leo Giesen
Leo Giesen

Reputation: 136

This worked for me:

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

So it is either history: createWebHashHistory(), or the createRouter.

Upvotes: 1

Related Questions