Skip to content

Conversation

@mehdibha
Copy link
Contributor

@mehdibha mehdibha commented Dec 22, 2025

The current Tanstack Start routing setup doesn't handle external links properly. When passing a string href (e.g., <MenuItem href="https://github.com">), the router's navigate and buildLocation methods fail with:

String.prototype.search called on null or undefined

Added type guards to handle string hrefs separately:

<RouterProvider
  navigate={(href, opts) => {
    if (typeof href === "string") return;
    router.navigate({ ...href, ...opts });
  }}
  useHref={(href) => {
    if (typeof href === "string") return href;
    return router.buildLocation(href).href;
  }}
>

stunaz
stunaz previously requested changes Dec 31, 2025
useHref={href => router.buildLocation(href).href}>
navigate={(href, opts) => {
if (typeof href === "string") return;
router.navigate({ ...href, ...opts });
Copy link

Choose a reason for hiding this comment

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

return router.navigate({ ...href, ...opts });

@snowystinger snowystinger added this pull request to the merge queue Jan 7, 2026
Merged via the queue into adobe:main with commit 953488a Jan 7, 2026
31 checks passed
navigate: (href, opts) => router.navigate({...href, ...opts}),
useHref: href => router.buildLocation(href).href
navigate: (href, opts) => {
if (typeof href === "string") return;
Copy link
Member

Choose a reason for hiding this comment

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

Does this case actually occur? Wouldn't that mean nothing happens when you click the link?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants