0

Hello i have some problem i want to push params in url to another page in NuxtJs

props: {
    idPending: {
      type: Number,
      required: true
    }
},

methods: {
    fetchpage() {
      const orderId = this.idPending;
      this.$router.push(
        this.localePath({
          name: 'Checkout-Confirmation-orderId', // page with params orderId
          params: { orderId: orderId }
        })
      );
    }
  }

when i do that i have this error i don't understand why

Argument type {name: string, params: {orderId: Number}} is not assignable to parameter type RawLocation   Type Number is not assignable to type string 

Please help thank you

francky
  • 157
  • 1
  • 13

2 Answers2

1

The error is pretty self-explanatory indeed, you cannot a type other than String here.
A confirmation can be found here: https://github.com/vuejs/vue-router/issues/2895#issuecomment-523549070

You could use String(orderId), from what I saw it is maybe faster but mainly safer because it does not produce any error in case of your orderId being null or undefined.

kissu
  • 40,416
  • 14
  • 65
  • 133
0

I answer mY question

Everything that can be passed as parameters between pages is always of type String and nothing else in my case my props id is of type Number hence the error I'm transform type to string in params like this

fetchpage() {
      const orderId = this.idPending;
      this.$router.push(
        this.localePath({
          name: 'Checkout-Confirmation-orderId', // page with params orderId
          params: { orderId: orderId.toString() }
        })
      );
    }
francky
  • 157
  • 1
  • 13