MCPcopy
hub / github.com/TanStack/router / Component

Function Component

packages/react-router/tests/optional-path-params.test.tsx:595–637  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

593 })
594
595 function Component() {
596 const navigate = useNavigate()
597 const params = postsRoute.useParams()
598
599 return (
600 <div>
601 <div data-testid="params">{JSON.stringify(params)}</div>
602 <button
603 data-testid="navigate-all"
604 onClick={() =>
605 navigate({
606 to: '/posts/{-$category}/{-$slug}',
607 params: false,
608 })
609 }
610 >
611 All Posts
612 </button>
613 <button
614 data-testid="navigate-tech"
615 onClick={() =>
616 navigate({
617 to: '/posts/{-$category}/{-$slug}',
618 params: { category: 'tech', slug: undefined },
619 })
620 }
621 >
622 Tech Posts
623 </button>
624 <button
625 data-testid="navigate-specific"
626 onClick={() =>
627 navigate({
628 to: '/posts/{-$category}/{-$slug}',
629 params: { category: 'tech', slug: 'hello-world' },
630 })
631 }
632 >
633 Specific Post
634 </button>
635 </div>
636 )
637 }
638 // Start at a specific post
639 window.history.replaceState({}, '', '/posts/tech/hello-world')
640

Callers

nothing calls this directly

Calls 2

useNavigateFunction · 0.90
navigateFunction · 0.50

Tested by

no test coverage detected