@tanstack/react-router 0.0.1-alpha.3 → 0.0.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-alpha.3",
4
+ "version": "0.0.1-alpha.5",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://react-router.tanstack.com/",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@babel/runtime": "^7.16.7",
43
- "@tanstack/router-core": "0.0.1-alpha.3",
43
+ "@tanstack/router-core": "0.0.1-alpha.5",
44
44
  "use-sync-external-store": "^1.2.0"
45
45
  },
46
46
  "devDependencies": {
package/src/index.tsx CHANGED
@@ -6,7 +6,6 @@ import {
6
6
  AnyRoute,
7
7
  RootRouteId,
8
8
  rootRouteId,
9
- Route,
10
9
  Router,
11
10
  } from '@tanstack/router-core'
12
11
  import {
@@ -29,6 +28,7 @@ import {
29
28
  ResolveRelativePath,
30
29
  NoInfer,
31
30
  ToOptions,
31
+ invariant,
32
32
  } from '@tanstack/router-core'
33
33
 
34
34
  export * from '@tanstack/router-core'
@@ -323,48 +323,45 @@ export function createReactRouter<
323
323
  useRoute: (routeId) => {
324
324
  const route = router.getRoute(routeId)
325
325
  useRouterSubscription(router)
326
- if (!route) {
327
- throw new Error(
328
- `Could not find a route for route "${
329
- routeId as string
330
- }"! Did you forget to add it to your route config?`,
331
- )
332
- }
326
+ invariant(
327
+ route,
328
+ `Could not find a route for route "${
329
+ routeId as string
330
+ }"! Did you forget to add it to your route config?`,
331
+ )
333
332
  return route
334
333
  },
335
334
  useMatch: (routeId) => {
336
- if (routeId === rootRouteId) {
337
- throw new Error(
338
- `"${rootRouteId}" cannot be used with useMatch! Did you mean to useRoute("${rootRouteId}")?`,
339
- )
340
- }
335
+ invariant(
336
+ routeId !== rootRouteId,
337
+ `"${rootRouteId}" cannot be used with useMatch! Did you mean to useRoute("${rootRouteId}")?`,
338
+ )
339
+
341
340
  const runtimeMatch = useMatch()
342
341
  const match = router.state.matches.find((d) => d.routeId === routeId)
343
342
 
344
- if (!match) {
345
- throw new Error(
346
- `Could not find a match for route "${
347
- routeId as string
348
- }" being rendered in this component!`,
349
- )
350
- }
351
-
352
- if (runtimeMatch.routeId !== match?.routeId) {
353
- throw new Error(
354
- `useMatch('${
355
- match?.routeId as string
356
- }') is being called in a component that is meant to render the '${
357
- runtimeMatch.routeId
358
- }' route. Did you mean to 'useRoute(${
359
- match?.routeId as string
360
- })' instead?`,
361
- )
362
- }
343
+ invariant(
344
+ match,
345
+ `Could not find a match for route "${
346
+ routeId as string
347
+ }" being rendered in this component!`,
348
+ )
349
+
350
+ invariant(
351
+ runtimeMatch.routeId == match?.routeId,
352
+ `useMatch('${
353
+ match?.routeId as string
354
+ }') is being called in a component that is meant to render the '${
355
+ runtimeMatch.routeId
356
+ }' route. Did you mean to 'useRoute(${
357
+ match?.routeId as string
358
+ })' instead?`,
359
+ )
363
360
 
364
361
  useRouterSubscription(router)
365
362
 
366
363
  if (!match) {
367
- throw new Error('Match not found!')
364
+ invariant('Match not found!')
368
365
  }
369
366
 
370
367
  return match