Vue Router: how to cast params as integers instead of strings?

You have to handle casting any params values yourself. In the route object define a props function. Here is an example:

{
  path: '/user/:userId',
  component: UserProfile,
  props: (route) => {
    /**
     * This would preserve the other route.params object properties overriding only 
     * `userId` in case it exists with its integer equivalent, or otherwise with 
     * undefined.
     */
    return { ...route.params, ...{ userId: Number.parseInt(route.params.userId, 10) || undefined }
  }
}

link to vue router docs this is under Function mode

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)