File tree Expand file tree Collapse file tree 3 files changed +16
-16
lines changed
Expand file tree Collapse file tree 3 files changed +16
-16
lines changed Original file line number Diff line number Diff line change 55use Illuminate \Foundation \Inspiring ;
66use Illuminate \Http \Request ;
77use Inertia \Middleware ;
8+ use Tighten \Ziggy \Ziggy ;
89
910class HandleInertiaRequests extends Middleware
1011{
@@ -38,13 +39,16 @@ public function share(Request $request): array
3839 {
3940 [$ message , $ author ] = str (Inspiring::quotes ()->random ())->explode ('- ' );
4041
41- return [
42- ...parent ::share ($ request ),
42+ return array_merge (parent ::share ($ request ), [
4343 'name ' => config ('app.name ' ),
4444 'quote ' => ['message ' => trim ($ message ), 'author ' => trim ($ author )],
4545 'auth ' => [
4646 'user ' => $ request ->user (),
4747 ],
48- ];
48+ 'ziggy ' => [
49+ ...(new Ziggy )->toArray (),
50+ 'location ' => $ request ->url (),
51+ ],
52+ ]);
4953 }
5054}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import Heading from '@/components/Heading.vue';
33import { Button } from ' @/components/ui/button' ;
44import { Separator } from ' @/components/ui/separator' ;
55import { type NavItem } from ' @/types' ;
6- import { Link } from ' @inertiajs/vue3' ;
6+ import { Link , usePage } from ' @inertiajs/vue3' ;
77
88const sidebarNavItems: NavItem [] = [
99 {
@@ -20,8 +20,9 @@ const sidebarNavItems: NavItem[] = [
2020 },
2121];
2222
23- // For SSR, we can't access the window location
24- const currentPath = (typeof window === ' undefined' ) ? ' ' : window .location .pathname ;
23+ // Get the current path from Ziggy config
24+ const page = usePage ();
25+ const currentPath = page .props .ziggy ?.location ? new URL (page .props .ziggy .location ).pathname : ' ' ;
2526 </script >
2627
2728<template >
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ createServer((page) =>
1414 title : ( title ) => `${ title } - ${ appName } ` ,
1515 resolve : ( name ) => resolvePageComponent ( `./pages/${ name } .vue` , import . meta. glob ( './pages/**/*.vue' ) ) ,
1616 setup ( { App, props, plugin } ) {
17+ const app = createSSRApp ( { render : ( ) => h ( App , props ) } )
18+
1719 // Configure Ziggy for SSR
1820 const ziggyConfig = {
1921 ...page . props . ziggy ,
@@ -24,21 +26,14 @@ createServer((page) =>
2426 const route = ( name : string , params ?: any , absolute ?: boolean ) =>
2527 ziggyRoute ( name , params , absolute , ziggyConfig )
2628
29+ // Make route function available globally
30+ app . config . globalProperties . route = route
31+
2732 // Make route function available globally for SSR
2833 if ( typeof window === 'undefined' ) {
2934 global . route = route
3035 }
3136
32- // Create the SSR app with route function in context
33- const app = createSSRApp ( {
34- render : ( ) => h ( App , props ) ,
35- setup ( ) {
36- return {
37- route,
38- }
39- } ,
40- } )
41-
4237 app . use ( plugin )
4338
4439 return app
You can’t perform that action at this time.
0 commit comments