File tree Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import type { HandleClientFetch } from '@sveltejs/kit' ;
2
+
3
+ export const handleFetch : HandleClientFetch = async ( { request, fetch } ) => {
4
+ // You can modify the request here if needed
5
+ if ( request . url . startsWith ( location . origin ) ) {
6
+ request . headers . set ( 'X-Client-Header' , 'imtheclient' ) ;
7
+ }
8
+
9
+ return await fetch ( request ) ;
10
+ } ;
Original file line number Diff line number Diff line change 13
13
<a href =" /c" >/c</a >
14
14
<a href =" /d" >/d</a >
15
15
<a href =" /e" >/e</a >
16
+ <a href =" /client-fetch" >/client-fetch</a >
16
17
</nav >
17
18
18
19
{@render children ()}
Original file line number Diff line number Diff line change
1
+ import type { PageServerLoad } from './$types' ;
2
+
3
+ export const load : PageServerLoad = ( { request } ) => {
4
+ const client_header = request . headers . get ( 'x-client-header' ) ;
5
+ console . log ( 'client header:' , client_header ) ;
6
+
7
+ return {
8
+ header : client_header
9
+ } ;
10
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let { data } = $props ();
3
+ </script >
4
+
5
+ <p >If you navigate from client-side, you should have an header set by handleFetch:</p >
6
+ <div >header: {data .header }</div >
You can’t perform that action at this time.
0 commit comments