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

Function setupRouter

packages/solid-router/tests/useNavigate.test.tsx:1480–1606  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1478 'relative useNavigate with %s',
1479 ({ basepath }) => {
1480 const setupRouter = () => {
1481 const rootRoute = createRootRoute()
1482 const indexRoute = createRoute({
1483 getParentRoute: () => rootRoute,
1484 path: '/',
1485 component: () => {
1486 return <h1>Index Route</h1>
1487 },
1488 })
1489 const aRoute = createRoute({
1490 getParentRoute: () => rootRoute,
1491 path: 'a',
1492 component: () => {
1493 return (
1494 <>
1495 <h1>A Route</h1>
1496 <Outlet />
1497 </>
1498 )
1499 },
1500 })
1501
1502 const bRoute = createRoute({
1503 getParentRoute: () => aRoute,
1504 path: 'b',
1505 component: function BRoute() {
1506 const navigate = useNavigate()
1507 return (
1508 <>
1509 <h1>B Route</h1>
1510 <button onClick={() => navigate({ to: '..' })}>
1511 Link to Parent
1512 </button>
1513 </>
1514 )
1515 },
1516 })
1517
1518 const paramRoute = createRoute({
1519 getParentRoute: () => rootRoute,
1520 path: 'param/$param',
1521 component: function ParamRoute() {
1522 const navigate = useNavigate()
1523 return (
1524 <>
1525 <h1>Param Route</h1>
1526 <button
1527 onClick={() =>
1528 navigate({ from: paramRoute.fullPath, to: './a' })
1529 }
1530 >
1531 Link to ./a
1532 </button>
1533 <button
1534 onClick={() => navigate({ params: { param: 'bar' } as any })}
1535 >
1536 Link to . with param:bar
1537 </button>

Callers 1

Calls 5

createRootRouteFunction · 0.90
createRouteFunction · 0.90
useNavigateFunction · 0.90
createRouterFunction · 0.90
navigateFunction · 0.50

Tested by

no test coverage detected