platform
platform copied to clipboard
URL not updated in browser after clicking a Link
Describe the bug
I have a Link
which heads to a Controller independent of the dashboard functionality which return redirect()->back()
- the route of the link is visited and changes in the browser, however the URL is not then updated after the redirect back.
// Link
Link::make('Refresh Access Token')
->icon('icon-refresh')
->route('bank-connections.refresh-access-token', $this->request->route('bank_connection')),
To Reproduce Steps to reproduce the behavior:
- Create a Link on an edit page to a Controller
- Perform some action in the Controller (add an
Alert
orToast
to see feedback in the dashboard - Assert the URL in the browser changes to the Link route
- Assert the URL does not change back to the original
Expected behavior
When a Controller returns redirect()->back()
or to any route, the URL in the browser should be updated
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Mac Mojave
- Browser: Chrome
- Version: 79.0.3
Server (please complete the following information):
- Laravel Version: 6.2
- PHP Version: 7.3.12
- Database: MySQL
- Database Version: 8
Additional context
There are no errors reported in the console. I also attempted to return the User back()
by returning the route return redirect()->route($routeName, $routeParams);
, I also redirected the User to an entirely different page on the dashboard, and the URL did not update
This is because turbolinks handles redirects in this way. This can be found here https://github.com/turbolinks/turbolinks#following-redirects
Currently, there are two solutions:
- Add header:
$response->header('Turbolinks-Location', $request->url());
- Add
->rawClick
method forLink::make()
This is not a mistake, but we could come up with something to facilitate the solution of such things. How about adding a middleware that added this to every request:
class TurbolinksLocation
{
/**
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);
return ($response instanceof BinaryFileResponse || $response instanceof StreamedResponse)
? $response
: $response->header('Turbolinks-Location', $request->url());
}
}
Hi @mdcass in the release under the number 6.10.0 the necessary middleware was added. For private routes, it is applied automatically. For the rest, it must be added manually.
For example:
Route::middleware(TurbolinksLocation::class)->group(static function () {
Route::get('/', static function () {
// your code...
});
});
Or add it to the desired section in app/Http/Kernel.php
, example:
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
//...
// Need to add
\Orchid\Platform\Http\Middleware\TurbolinksLocation::class
],
'api' => [
'throttle:60,1',
'bindings',
],
];
Brillaint, thanks so much for your quick work
I noticed that https://github.com/turbolinks/turbolinks is no longer under active development. Would that be a problem since Orchid relies on it?