Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Vue-router keeps appending # to existing routes. P.S this isn't the typical hash, history mode issue

Using Vue 3, i have my router file set up this way

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


const routes = [
    {
        path: "/",
        name: "Home",
        component: Home,
    },
    {
        path: "/Portfolio",
        name: "Portfolio",
        component: () =>
            import(/*webpackChunkName: "DestinationDetails" */ "../views/Portfolio"),
    },
    {
        path: "/Services",
        name: "Services",
        component: () =>
            import(/*webpackChunkName: "DestinationDetails" */ "../views/Services"),
    },

    {
        path: "/details/:id",
        name: "PortfolioDetails",
        component: () =>
            import(
                /*webpackChunkName: "DestinationDetails" */ "../views/PortfolioDetails"
            ),
    },
    {
        path: "/:pathMatch(.*)*",
        redirect: "/Home",
    },
];

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

export default router;

I am also running a v-for loop to get paths from an API "https://api.fake.rest/ca2a6662-22d0-4010-ba08-0440ffe813ab/menu". 3 of the 5 url paths have a value of "#". the remaining two have normal paths.

<div
                    v-for="(men, index) in webMenu.menu_items"
                    :key="index"  class=" mt-32"
                >
                    <!-- <SidebarLink class="w-full" :to="{path:men.url}" icon="fas fa-home">{{
                        men.name
                    }}</SidebarLink> -->

                    <router-link class="w-full" :to="men.url"> {{men.name}} </router-link>
                </div>

                <p class="font-bold">{{webMenu.menu_text}}</p>
            </div>

Problem is now when the webpage loads initially, it works fine but after clicking on the portfolio or services link, the paths to the others are changed.

e.g if i was on the portfolio page and tried switching back to the home page, it would change the route path to "portfolio#" and refuse to switch pages.

Can anyone help explain why this is and a possible way to resolve it?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I was also facing the similar issue.

For me the problem was that I was redirecting to a new page using router.push() when clicking on a div.

And I was using @click.stop = "myFunction" . This was adding a # in the URL and not redirecting the user.

I tried different variations of this as well. I tried to use the event object also like event.stopPropagation() . With this I also got the same result.

When I used @click.prevent , everything worked as expected.

P.S:

You can also use the catch block to trace the error.

 this.$router..push({ name: "PAthName", params: { id }, query: { id } }) .catch(e => { console.log("Errors", e); });
about 4 years ago · Juan Pablo Isaza Relatório

0

Should have updated this earlier.

The fix was relatively simple, all i did was change the binding from

<router-link class="w-full" :to="men.url"> {{men.name}} </router-link>

to

<router-link class="w-full" :to="`/${men.url}`"> {{men.name}} </router-link>

and voila!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda