Skip to content

Commit

Permalink
livewire navigation links
Browse files Browse the repository at this point in the history
  • Loading branch information
jkimble committed Oct 21, 2024
1 parent 1463d92 commit e5f8764
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/Livewire/CreatePosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function save()
'post_content' => $this->content
]);

$this->redirect('/posts');
$this->redirect('/posts', navigate: true);
/*
navigate: true here allows you to use livewire ajax navigation for redirects
*/
}
}
6 changes: 3 additions & 3 deletions resources/views/components/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
</head>
<body>
<nav>
<a href="/" @class(['current' => request()->is('/')])>Todo</a>
<a href="/counter" @class(['current' => request()->is('counter')])>Counter</a>
<a href="/posts" @class(['current' => request()->is('posts')])>Posts</a>
<a wire:navigate {{-- can add this on any link to make ajax --}} href="/" @class(['current' => request()->is('/')])>Todo</a>
<a wire:navigate href="/counter" @class(['current' => request()->is('counter')])>Counter</a>
<a wire:navigate href="/posts" @class(['current' => request()->is('posts')])>Posts</a>
</nav>
{{ $slot }}
</body>
Expand Down

0 comments on commit e5f8764

Please sign in to comment.