router hash(#) symbol in vue 3

Viewed 37

I am using createWebHistory but it still stays in my hash url link localhost/#/projects Am I missing something while writing the code? How can i remove # symbol?

router

    const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    redirect: "/projects",
    component: () => import("@/layout-newLayout.vue"),
    children: [
      {
        path: "/projects",
        name: "projects",
        component: () => import("@/views/projects/index.vue"),
      },
    ],
  },
]

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

The use of the 'hash' comes from the history mode you are using. You can change the mode to several others, but note for some you will need to add some server-side support if you wish to allow the URL to link back into the application.

Full details and code samples in the documentation.

Related