'InertiaJS redirecting to another components does not render
I'm using Laravel and InertiaJS and Vue 3 to create an application. I have a simple login page (username and password only), When the user logs in, I want to redirect him to the homepage. I have two Vue components - Login and Home.
This the function I'm using in LoginController:
public function store() {
$attributes = request() -> validate([
'username' => 'required|min:4',
'password' => 'required|min:8',
]);
if(auth()->attempt($attributes)) // <-- returns true.
return Route::redirect('/home');
}
I have this Route in my web.php:
Route::get('/home', function() {
return Inertia::render('Home');
})
When the user tries to login, it logs in correctly, but does not refresh. after manual refresh the user does gets to the homepage, but I want the redirection to be automatic.
The post request to store is through axios, I have this on my Login.Vue:
login() {
axios.post('login', {
username: this.username,
password: this.password
})
}
I read the docs, and saw few questions here, but it didn't work for me for some reason.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
