@@ -214,6 +214,20 @@ function getActiveMatches(
214
214
215
215
export const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css" ;
216
216
217
+ /**
218
+ * Props for the {@link Links} component.
219
+ *
220
+ * @category Types
221
+ */
222
+ export interface LinksProps {
223
+ /**
224
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
225
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
226
+ * element
227
+ */
228
+ nonce ?: string | undefined ;
229
+ }
230
+
217
231
/**
218
232
* Renders all the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
219
233
* tags created by the route module's [`links`](../../start/framework/route-module#links)
@@ -237,10 +251,12 @@ export const CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
237
251
* @public
238
252
* @category Components
239
253
* @mode framework
254
+ * @param props Props
255
+ * @param {LinksProps.nonce } props.nonce n/a
240
256
* @returns A collection of React elements for [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
241
257
* tags
242
258
*/
243
- export function Links ( ) : React . JSX . Element {
259
+ export function Links ( { nonce } : LinksProps ) : React . JSX . Element {
244
260
let { isSpaMode, manifest, routeModules, criticalCss } =
245
261
useFrameworkContext ( ) ;
246
262
let { errors, matches : routerMatches } = useDataRouterStateContext ( ) ;
@@ -265,13 +281,14 @@ export function Links(): React.JSX.Element {
265
281
{ ...{ [ CRITICAL_CSS_DATA_ATTRIBUTE ] : "" } }
266
282
rel = "stylesheet"
267
283
href = { criticalCss . href }
284
+ nonce = { nonce }
268
285
/>
269
286
) : null }
270
287
{ keyedLinks . map ( ( { key, link } ) =>
271
288
isPageLinkDescriptor ( link ) ? (
272
- < PrefetchPageLinks key = { key } { ...link } />
289
+ < PrefetchPageLinks key = { key } nonce = { nonce } { ...link } />
273
290
) : (
274
- < link key = { key } { ...link } />
291
+ < link key = { key } nonce = { nonce } { ...link } />
275
292
) ,
276
293
) }
277
294
</ >
@@ -463,7 +480,7 @@ function PrefetchPageLinksImpl({
463
480
{ keyedPrefetchLinks . map ( ( { key, link } ) => (
464
481
// these don't spread `linkProps` because they are full link descriptors
465
482
// already with their own props
466
- < link key = { key } { ...link } />
483
+ < link key = { key } nonce = { linkProps . nonce } { ...link } />
467
484
) ) }
468
485
</ >
469
486
) ;
0 commit comments