Skip to content
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

fix: Repair catch-all route params couldn't be mixed with other params #25

Merged
merged 4 commits into from
Aug 17, 2024

Conversation

Katona
Copy link
Contributor

@Katona Katona commented Aug 15, 2024

This PR fixes the issue of catch_all route params can't be mixed with others, like:

        const { routes } = createNavigationConfig((defineRoute) => ({
          organizationUser: defineRoute(
            '/organizations/[orgId]/users/[userId]/[[...catch_all]]',
            {
              params: z.object({
                orgId: z.string(),
                userId: z.string(),
                catch_all: z.array(z.string()).default([])
              }),
            },
          ),
        }));

@@ -22,9 +22,9 @@ type Suffix = `?${string}`;
type SafePath<Path extends string> = string extends Route ? Path : Route<Path>;

type ExtractPathParams<T extends string> =
T extends `${string}[[...${infer Param}]]${infer Rest}` ?
T extends `${infer Rest}[[...${infer Param}]]` ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch-all params are supposed to be the last one, so we 'parse' them from right to left.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @Katona

@Katona Katona marked this pull request as ready for review August 15, 2024 15:23
Copy link
Owner

@lukemorales lukemorales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Katona!

Can you generate a changeset using bun changeset with a patch version for it?

@@ -22,9 +22,9 @@ type Suffix = `?${string}`;
type SafePath<Path extends string> = string extends Route ? Path : Route<Path>;

type ExtractPathParams<T extends string> =
T extends `${string}[[...${infer Param}]]${infer Rest}` ?
T extends `${infer Rest}[[...${infer Param}]]` ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @Katona

@Katona
Copy link
Contributor Author

Katona commented Aug 17, 2024

@lukemorales I have added the changeset. I have never used it before, let me know if I have missed something.

@lukemorales
Copy link
Owner

@lukemorales I have added the changeset. I have never used it before, let me know if I have missed something.

That looks good! Also, it looks like CI is failing on the linting step, could you fix that? Then we're good to merge

@lukemorales lukemorales changed the title Fix catch-all route params couldn't be mixed with other params fix: Repair catch-all route params couldn't be mixed with other params Aug 17, 2024
Copy link
Owner

@lukemorales lukemorales left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great contribution! Thanks for the PR @Katona

@lukemorales lukemorales merged commit 711f5f6 into lukemorales:main Aug 17, 2024
5 checks passed
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