@tanstack/react-router 1.129.8 → 1.130.0
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/dist/cjs/Matches.cjs +4 -2
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/esm/Matches.js +4 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/llms/rules/api.d.ts +1 -1
- package/dist/llms/rules/api.js +77 -2
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +43 -49
- package/package.json +3 -3
- package/src/Matches.tsx +20 -13
package/dist/llms/rules/guide.js
CHANGED
|
@@ -164,6 +164,22 @@ You can _optionally_, also use the [Non-Redirected Authentication](#non-redirect
|
|
|
164
164
|
|
|
165
165
|
This approach can also be used in conjunction with Pathless or Layout Route to protect all routes under their parent route.
|
|
166
166
|
|
|
167
|
+
## Related How-To Guides
|
|
168
|
+
|
|
169
|
+
For detailed, step-by-step implementation guides, see:
|
|
170
|
+
|
|
171
|
+
- [How to Set Up Basic Authentication](../how-to/setup-authentication.md) - Complete setup with React Context and protected routes
|
|
172
|
+
- [How to Integrate Authentication Providers](../how-to/setup-auth-providers.md) - Use Auth0, Clerk, or Supabase
|
|
173
|
+
- [How to Set Up Role-Based Access Control](../how-to/setup-rbac.md) - Implement permissions and role-based routing
|
|
174
|
+
|
|
175
|
+
## Examples
|
|
176
|
+
|
|
177
|
+
Working authentication examples are available in the repository:
|
|
178
|
+
|
|
179
|
+
- [Basic Authentication Example](https://github.com/TanStack/router/tree/main/examples/react/authenticated-routes) - Simple authentication with context
|
|
180
|
+
- [Firebase Authentication](https://github.com/TanStack/router/tree/main/examples/react/authenticated-routes-firebase) - Firebase Auth integration
|
|
181
|
+
- [TanStack Start Auth Examples](https://github.com/TanStack/router/tree/main/examples/react) - Various auth implementations with TanStack Start
|
|
182
|
+
|
|
167
183
|
# Automatic Code Splitting
|
|
168
184
|
|
|
169
185
|
The automatic code splitting feature in TanStack Router allows you to optimize your application's bundle size by lazily loading route components and their associated data. This is particularly useful for large applications where you want to minimize the initial load time by only loading the necessary code for the current route.
|
|
@@ -361,7 +377,7 @@ export default defineConfig({
|
|
|
361
377
|
})
|
|
362
378
|
\`\`\`
|
|
363
379
|
|
|
364
|
-
We highly discourage splitting the \`loader\` unless you have a specific use case that requires it. In most cases,
|
|
380
|
+
We highly discourage splitting the \`loader\` unless you have a specific use case that requires it. In most cases, not splitting off the \`loader\` and keep it in the main bundle is the best choice for performance.
|
|
365
381
|
|
|
366
382
|
# Code Splitting
|
|
367
383
|
|
|
@@ -376,7 +392,6 @@ Code splitting and lazy loading is a powerful technique for improving the bundle
|
|
|
376
392
|
TanStack Router separates code into two categories:
|
|
377
393
|
|
|
378
394
|
- **Critical Route Configuration** - The code that is required to render the current route and kick off the data loading process as early as possible.
|
|
379
|
-
|
|
380
395
|
- Path Parsing/Serialization
|
|
381
396
|
- Search Param Validation
|
|
382
397
|
- Loaders, Before Load
|
|
@@ -796,59 +811,38 @@ Here are some examples of how you can use \`createLink\` with third-party librar
|
|
|
796
811
|
|
|
797
812
|
### React Aria Components example
|
|
798
813
|
|
|
799
|
-
React Aria Components'
|
|
800
|
-
[Link](https://react-spectrum.adobe.com/react-aria/Link.html) component does not support the standard \`onMouseEnter\` and \`onMouseLeave\` events.
|
|
801
|
-
Therefore, you cannot use it directly with TanStack Router's \`preload (intent)\` prop.
|
|
814
|
+
React Aria Components v1.11.0 and later works with TanStack Router's \`preload (intent)\` prop. Use \`createLink\` to wrap each React Aria component that you use as a link.
|
|
802
815
|
|
|
803
|
-
|
|
816
|
+
\`\`\`tsx
|
|
817
|
+
import { createLink } from '@tanstack/react-router'
|
|
818
|
+
import { Link as RACLink, MenuItem } from 'react-aria-components'
|
|
804
819
|
|
|
805
|
-
|
|
806
|
-
|
|
820
|
+
export const Link = createLink(RACLink)
|
|
821
|
+
export const MenuItemLink = createLink(MenuItem)
|
|
822
|
+
\`\`\`
|
|
807
823
|
|
|
808
|
-
|
|
824
|
+
To use React Aria's render props, including the \`className\`, \`style\`, and \`children\` functions, create a wrapper component and pass that to \`createLink\`.
|
|
809
825
|
|
|
810
826
|
\`\`\`tsx
|
|
811
|
-
import
|
|
812
|
-
import {
|
|
813
|
-
import {
|
|
814
|
-
mergeProps,
|
|
815
|
-
useFocusRing,
|
|
816
|
-
useHover,
|
|
817
|
-
useLink,
|
|
818
|
-
useObjectRef,
|
|
819
|
-
} from 'react-aria'
|
|
820
|
-
import type { AriaLinkOptions } from 'react-aria'
|
|
827
|
+
import { createLink } from '@tanstack/react-router'
|
|
828
|
+
import { Link as RACLink, type LinkProps } from 'react-aria-components'
|
|
821
829
|
|
|
822
|
-
interface
|
|
823
|
-
|
|
830
|
+
interface MyLinkProps extends LinkProps {
|
|
831
|
+
// your props
|
|
824
832
|
}
|
|
825
833
|
|
|
826
|
-
|
|
827
|
-
(
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
<a
|
|
836
|
-
{...mergeProps(linkProps, hoverProps, focusProps, props)}
|
|
837
|
-
ref={ref}
|
|
838
|
-
data-hovered={isHovered || undefined}
|
|
839
|
-
data-pressed={isPressed || undefined}
|
|
840
|
-
data-focus-visible={isFocusVisible || undefined}
|
|
841
|
-
data-focused={isFocused || undefined}
|
|
842
|
-
/>
|
|
843
|
-
)
|
|
844
|
-
},
|
|
845
|
-
)
|
|
846
|
-
|
|
847
|
-
const CreatedLinkComponent = createLink(RACLinkComponent)
|
|
848
|
-
|
|
849
|
-
export const CustomLink: LinkComponent<typeof RACLinkComponent> = (props) => {
|
|
850
|
-
return <CreatedLinkComponent preload={'intent'} {...props} />
|
|
834
|
+
function MyLink(props: MyLinkProps) {
|
|
835
|
+
return (
|
|
836
|
+
<RACLink
|
|
837
|
+
{...props}
|
|
838
|
+
style={({ isHovered }) => ({
|
|
839
|
+
color: isHovered ? 'red' : 'blue',
|
|
840
|
+
})}
|
|
841
|
+
/>
|
|
842
|
+
)
|
|
851
843
|
}
|
|
844
|
+
|
|
845
|
+
export const Link = createLink(MyLink)
|
|
852
846
|
\`\`\`
|
|
853
847
|
|
|
854
848
|
### Chakra UI example
|
|
@@ -2112,9 +2106,9 @@ export const Route = createRootRoute({
|
|
|
2112
2106
|
children: \`p {
|
|
2113
2107
|
color: blue;
|
|
2114
2108
|
background-color: yellow;
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
]
|
|
2109
|
+
}\`,
|
|
2110
|
+
},
|
|
2111
|
+
],
|
|
2118
2112
|
scripts: [
|
|
2119
2113
|
{
|
|
2120
2114
|
src: 'https://www.google-analytics.com/analytics.js',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.130.0",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"isbot": "^5.1.22",
|
|
80
80
|
"tiny-invariant": "^1.3.3",
|
|
81
81
|
"tiny-warning": "^1.0.3",
|
|
82
|
-
"@tanstack/
|
|
83
|
-
"@tanstack/
|
|
82
|
+
"@tanstack/router-core": "1.130.0",
|
|
83
|
+
"@tanstack/history": "1.129.7"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@testing-library/jest-dom": "^6.6.3",
|
package/src/Matches.tsx
CHANGED
|
@@ -67,6 +67,7 @@ export function Matches() {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
function MatchesInner() {
|
|
70
|
+
const router = useRouter()
|
|
70
71
|
const matchId = useRouterState({
|
|
71
72
|
select: (s) => {
|
|
72
73
|
return s.matches[0]?.id
|
|
@@ -77,21 +78,27 @@ function MatchesInner() {
|
|
|
77
78
|
select: (s) => s.loadedAt,
|
|
78
79
|
})
|
|
79
80
|
|
|
81
|
+
const matchComponent = matchId ? <Match matchId={matchId} /> : null
|
|
82
|
+
|
|
80
83
|
return (
|
|
81
84
|
<matchContext.Provider value={matchId}>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
{router.options.disableGlobalCatchBoundary ? (
|
|
86
|
+
matchComponent
|
|
87
|
+
) : (
|
|
88
|
+
<CatchBoundary
|
|
89
|
+
getResetKey={() => resetKey}
|
|
90
|
+
errorComponent={ErrorComponent}
|
|
91
|
+
onCatch={(error) => {
|
|
92
|
+
warning(
|
|
93
|
+
false,
|
|
94
|
+
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,
|
|
95
|
+
)
|
|
96
|
+
warning(false, error.message || error.toString())
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{matchComponent}
|
|
100
|
+
</CatchBoundary>
|
|
101
|
+
)}
|
|
95
102
|
</matchContext.Provider>
|
|
96
103
|
)
|
|
97
104
|
}
|