Skip to content

Commit 47869b7

Browse files
committed
refactor
1 parent 8788724 commit 47869b7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/router/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,19 @@ function matchRouteBranch<
465465
* @see https://reactrouter.com/docs/en/v6/utils/generate-path
466466
*/
467467
export function generatePath<Path extends string>(path: Path, params: {
468-
[key in PathParams<Path> | (string & {})]: string
468+
[key in PathParams<Path>]: string
469469
} = {} as any): string {
470470
return path
471-
.replace(/:(\w+)/g, (_, key) => {
471+
.replace(/:(\w+)/g, (_, key: PathParams<Path>) => {
472472
invariant(params[key] != null, `Missing ":${key}" param`);
473473
return params[key]!;
474474
})
475475
.replace(/\/*\*$/, (_) =>
476-
params["*"] == null ? "" : params["*"].replace(/^\/*/, "/")
476+
{
477+
const star = "*" as PathParams<Path>
478+
479+
return params[star] == null ? "" : params[star].replace(/^\/*/, "/")
480+
}
477481
);
478482
}
479483

0 commit comments

Comments
 (0)