Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ yarn-error.log
/.nova
/.vscode
/.zed
/bootstrap/ssr
5 changes: 5 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Foundation\Inspiring;
use Illuminate\Http\Request;
use Inertia\Middleware;
use Tighten\Ziggy\Ziggy;

class HandleInertiaRequests extends Middleware
{
Expand Down Expand Up @@ -45,6 +46,10 @@ public function share(Request $request): array
'auth' => [
'user' => $request->user(),
],
'ziggy' => fn (): array => [
...(new Ziggy)->toArray(),
'location' => $request->url(),
],
];
}
}
5 changes: 5 additions & 0 deletions resources/js/layouts/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const sidebarNavItems: NavItem[] = [
];

export default function SettingsLayout({ children }: { children: React.ReactNode }) {
// For SSR, we can't access the window location, so can only render the layout on the client
if (typeof window === 'undefined') {
return null;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is url in usePage hooks, why not just use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We certainly could, both will accomplish the same thing I'm pretty sure. This is just a preference of being explicit about rendering on the server.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess in that context I prefer that way too, thanks for the answer.


const currentPath = window.location.pathname;

return (
Expand Down
2 changes: 2 additions & 0 deletions resources/js/types/index.ts → resources/js/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LucideIcon } from 'lucide-react';
import type { Config } from "ziggy-js";

export interface Auth {
user: User;
Expand All @@ -25,6 +26,7 @@ export interface SharedData {
name: string;
quote: { message: string; author: string };
auth: Auth;
ziggy: Config & { location: string };
[key: string]: unknown;
}

Expand Down