I'm am trying to get a message to show after a post in React from a Laraval server using InertiaJS.
From what I can find in docs / online / in other (semi) related questions the following is an isolated version of what I think should work - I'm under the impression it should be added to my props. My Test component does reload so the redirect is working just with no message and props remaining undefined - What am I not understanding?
Laravel Controller:
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use Illuminate\Routing\Controller as BaseController;
class TestController extends BaseController
{
function test(){
return Inertia::render('Test');
}
function testResponse(){
//dd("I GET TO HERE, SO ITS NOT A ROUTING ISSUE!")
return Redirect::back()->with('message', 'Test message from server.');
}
}
My React Test Component
import { Link } from '@inertiajs/inertia-react';
import React from 'react';
const Test = (props) => {
const [serverMessage, setServerMessage] = useState('no message');
return <div>
<div>{serverMessage}</div>
<Link className="hover:bg-blue-700 bg-blue-400 text-white py-1 px-3 rounded" href={route('testResponse')} method="post" as="button">
Get Server Response
</Link>
</div>;
};
export default Test;