Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I use vue router to redirect to another website?

I’m using vue router in a project and I noticed that when I used the redirect property it redirected me to the same website.
for example if I have

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

const routes = [{
  {
    path: "/google",
    redirect: "https://www.google.com",
  },
];

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

export default router;

it will redirect me to domain.com/https://www.google.com
instead of straightly going to https://www.google.com
is there a way to prevent that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The following fixed OP’s issue.

const routes = [{
  {
    path: "/google",
    redirect: "https://www.google.com",
     beforeEnter: () => {
      window.location.href = 'http://www.google.com'
    },

  },
];

Using navigation guards.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading