Skip to content

fix: deduplicate identical route params #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Anoesj
Copy link
Contributor

@Anoesj Anoesj commented Mar 4, 2025

Right now, route params of nested routes are sometimes duplicated, e.g.:

/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️
// It's recommended to commit this file.
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.

declare module 'vue-router/auto-routes' {
  import type {
    RouteRecordInfo,
    ParamValue,
    ParamValueOneOrMore,
    ParamValueZeroOrMore,
    ParamValueZeroOrOne,
  } from 'vue-router'

  /**
   * Route name map generated by unplugin-vue-router
   */
  export interface RouteNamedMap {
    'projects': RouteRecordInfo<'projects', '/', Record<never, never>, Record<never, never>>,
    'project': RouteRecordInfo<'project', '/project/:projectId()', { projectId: ParamValue<true> }, { projectId: ParamValue<false> }>,
    'project-view': RouteRecordInfo<'project-view', '/project/:projectId', { projectId: ParamValue<true>, projectId: ParamValue<true> }, { projectId: ParamValue<false>, projectId: ParamValue<false> }>,
  }
}

This small change deduplicates params that are identical (on a string basis) and is probably basically a quickfix. I'm not sure if it's theoretically possible for a param to be included multiple times with different values? If more work is needed, let me know!

@Anoesj Anoesj force-pushed the dedupe-route-params branch from a4bf842 to f531db7 Compare March 4, 2025 19:25
@posva
Copy link
Owner

posva commented Mar 4, 2025

Thanks, but this should not be needed because the routes are stored in a tree, so there is no duplication

@Anoesj Anoesj closed this Mar 7, 2025
@Anoesj
Copy link
Contributor Author

Anoesj commented Mar 7, 2025

Apparently, I ran into a Nuxt issue, where params are duplicated in the tree when using definePageMeta to set the path property. Even if the provided path is identical to the path generated by unplugin-vue-router (or Nuxt?), the params are duplicated in the tree, and therefor in the typed router DTS. I closed this PR and will dig a little deeper into why this happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants