Home > Net >  redirection link generate by the methods to href or nuxt-link
redirection link generate by the methods to href or nuxt-link

Time:10-26

Hello I want to display a page with a link generated by a method.
Here is my current code.

<template>
  <nuxt-link :to="seeProduct(item.sku.product.id).toString()">
      <div>
        <span>Go to product</span>
      </div>
  </nuxt-link>
</template>

<script>
export default {
methods: {
  async seeProduct(id) {
    const app = { $axios: this.$axios };
    const urlProduct = await endPoint.getProduct(app, id);
    console.log(urlProduct.url); // https://www.products/gants.html => this is the url
    return urlProduct.url;
    },
  }
}
</script>

When I click on the link, the redirection is not good. How to do a good redirection with an URL generated by a method?

CodePudding user response:

If it's an internal path, I do recommend you passing an actual path only or even better, a name as shown here: https://router.vuejs.org/guide/essentials/navigation.html#router-push-location-oncomplete-onabort

It should look something like :to="{ name: 'gants' }" when your seeProduct method is done.

  • Related