Skip to content

Commit 2c37ce2

Browse files
authored
fix: use this.fullPath instead of useRouter (#4099)
1 parent 468edac commit 2c37ce2

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

packages/react-router/src/route.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,7 @@ export class Route<
257257

258258
Link: LinkComponent<'a', TFullPath> = React.forwardRef(
259259
(props, ref: React.ForwardedRef<HTMLAnchorElement>) => {
260-
const router = useRouter()
261-
return (
262-
<Link
263-
ref={ref}
264-
from={router.routesById[this.id].fullPath as never}
265-
{...props}
266-
/>
267-
)
260+
return <Link ref={ref} from={this.fullPath as never} {...props} />
268261
},
269262
) as unknown as LinkComponent<'a', TFullPath>
270263
}
@@ -455,14 +448,7 @@ export class RootRoute<
455448

456449
Link: LinkComponent<'a', '/'> = React.forwardRef(
457450
(props, ref: React.ForwardedRef<HTMLAnchorElement>) => {
458-
const router = useRouter()
459-
return (
460-
<Link
461-
ref={ref}
462-
from={router.routesById[this.id].fullPath as never}
463-
{...props}
464-
/>
465-
)
451+
return <Link ref={ref} from={this.fullPath} {...props} />
466452
},
467453
) as unknown as LinkComponent<'a', '/'>
468454
}

packages/solid-router/src/route.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,7 @@ export class Route<
243243
}
244244

245245
Link: LinkComponent<'a', TFullPath> = (props) => {
246-
const router = useRouter()
247-
const fullPath = router.routesById[this.id as string].fullPath
248-
return <Link from={fullPath as never} {...props} />
246+
return <Link from={this.fullPath} {...props} />
249247
}
250248
}
251249

@@ -430,9 +428,7 @@ export class RootRoute<
430428
}
431429

432430
Link: LinkComponent<'a', '/'> = (props) => {
433-
const router = useRouter()
434-
const fullPath = router.routesById[this.id as string].fullPath
435-
return <Link from={fullPath as never} {...props} />
431+
return <Link from={this.fullPath} {...props} />
436432
}
437433
}
438434

0 commit comments

Comments
 (0)