[Vuejs]-Vue Router – Default value for optional url parameter when a separate optional url parameter is set

0👍

I don’t think there is a way, but if there was then it couldn’t be considered optional. I suggest simply passing in the string ‘all’ if filters.getId() is null

updateRoute(): void {
  const filters = this.filters;
  const router = this.$router;

  let routeId = filters.getId()
  if (!routeId && filters.handedSlug()) {
    routeId = 'all'
  }

  router.push({
    name: 'Person',
    params: {
      id: routeId,
      handedSlug: filters.handedSlug(),
    },
  });
},

Leave a comment