@tanstack/react-router 1.121.21 → 1.121.24
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/Asset.cjs +83 -16
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/Asset.d.cts +2 -1
- package/dist/esm/Asset.d.ts +2 -1
- package/dist/esm/Asset.js +66 -16
- package/dist/esm/Asset.js.map +1 -1
- package/dist/llms/rules/guide.d.ts +1 -1
- package/dist/llms/rules/guide.js +2 -0
- package/package.json +1 -1
- package/src/Asset.tsx +95 -16
package/dist/llms/rules/guide.js
CHANGED
|
@@ -1957,6 +1957,8 @@ export const Route = createRootRoute({
|
|
|
1957
1957
|
|
|
1958
1958
|
### Single-Page Applications
|
|
1959
1959
|
|
|
1960
|
+
First, remove the \`<title>\` tag from the the index.html if you have set any.
|
|
1961
|
+
|
|
1960
1962
|
\`\`\`tsx
|
|
1961
1963
|
import { HeadContent } from '@tanstack/react-router'
|
|
1962
1964
|
|
package/package.json
CHANGED
package/src/Asset.tsx
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
1
2
|
import type { RouterManagedTag } from '@tanstack/router-core'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
interface ScriptAttrs {
|
|
5
|
+
[key: string]: string | boolean | undefined
|
|
6
|
+
src?: string
|
|
7
|
+
suppressHydrationWarning?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Asset({
|
|
11
|
+
tag,
|
|
12
|
+
attrs,
|
|
13
|
+
children,
|
|
14
|
+
}: RouterManagedTag): React.ReactElement | null {
|
|
4
15
|
switch (tag) {
|
|
5
16
|
case 'title':
|
|
6
17
|
return (
|
|
@@ -16,25 +27,93 @@ export function Asset({ tag, attrs, children }: RouterManagedTag): any {
|
|
|
16
27
|
return (
|
|
17
28
|
<style
|
|
18
29
|
{...attrs}
|
|
19
|
-
dangerouslySetInnerHTML={{ __html: children as
|
|
30
|
+
dangerouslySetInnerHTML={{ __html: children as string }}
|
|
20
31
|
/>
|
|
21
32
|
)
|
|
22
33
|
case 'script':
|
|
23
|
-
|
|
24
|
-
return <script {...attrs} suppressHydrationWarning />
|
|
25
|
-
}
|
|
26
|
-
if (typeof children === 'string')
|
|
27
|
-
return (
|
|
28
|
-
<script
|
|
29
|
-
{...attrs}
|
|
30
|
-
dangerouslySetInnerHTML={{
|
|
31
|
-
__html: children,
|
|
32
|
-
}}
|
|
33
|
-
suppressHydrationWarning
|
|
34
|
-
/>
|
|
35
|
-
)
|
|
36
|
-
return null
|
|
34
|
+
return <Script attrs={attrs}>{children}</Script>
|
|
37
35
|
default:
|
|
38
36
|
return null
|
|
39
37
|
}
|
|
40
38
|
}
|
|
39
|
+
|
|
40
|
+
function Script({
|
|
41
|
+
attrs,
|
|
42
|
+
children,
|
|
43
|
+
}: {
|
|
44
|
+
attrs?: ScriptAttrs
|
|
45
|
+
children?: string
|
|
46
|
+
}) {
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (attrs?.src) {
|
|
49
|
+
const script = document.createElement('script')
|
|
50
|
+
|
|
51
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
52
|
+
if (
|
|
53
|
+
key !== 'suppressHydrationWarning' &&
|
|
54
|
+
value !== undefined &&
|
|
55
|
+
value !== false
|
|
56
|
+
) {
|
|
57
|
+
script.setAttribute(
|
|
58
|
+
key,
|
|
59
|
+
typeof value === 'boolean' ? '' : String(value),
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
document.head.appendChild(script)
|
|
65
|
+
|
|
66
|
+
return () => {
|
|
67
|
+
if (script.parentNode) {
|
|
68
|
+
script.parentNode.removeChild(script)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof children === 'string') {
|
|
74
|
+
const script = document.createElement('script')
|
|
75
|
+
script.textContent = children
|
|
76
|
+
|
|
77
|
+
if (attrs) {
|
|
78
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
79
|
+
if (
|
|
80
|
+
key !== 'suppressHydrationWarning' &&
|
|
81
|
+
value !== undefined &&
|
|
82
|
+
value !== false
|
|
83
|
+
) {
|
|
84
|
+
script.setAttribute(
|
|
85
|
+
key,
|
|
86
|
+
typeof value === 'boolean' ? '' : String(value),
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
document.head.appendChild(script)
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
if (script.parentNode) {
|
|
96
|
+
script.parentNode.removeChild(script)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return undefined
|
|
102
|
+
}, [attrs, children])
|
|
103
|
+
|
|
104
|
+
if (attrs?.src && typeof attrs.src === 'string') {
|
|
105
|
+
return <script {...attrs} suppressHydrationWarning />
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeof children === 'string') {
|
|
109
|
+
return (
|
|
110
|
+
<script
|
|
111
|
+
{...attrs}
|
|
112
|
+
dangerouslySetInnerHTML={{ __html: children }}
|
|
113
|
+
suppressHydrationWarning
|
|
114
|
+
/>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return null
|
|
119
|
+
}
|