platform icon indicating copy to clipboard operation
platform copied to clipboard

URL not updated in browser after clicking a Link

Open mdcass opened this issue 5 years ago • 4 comments

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:

  1. Create a Link on an edit page to a Controller
  2. Perform some action in the Controller (add an Alert or Toast to see feedback in the dashboard
  3. Assert the URL in the browser changes to the Link route
  4. 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

mdcass avatar Feb 05 '20 11:02 mdcass

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 for Link::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());
    }
}

tabuna avatar Feb 05 '20 11:02 tabuna

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',
    ],
];

tabuna avatar Feb 06 '20 09:02 tabuna

Brillaint, thanks so much for your quick work

mdcass avatar Feb 07 '20 12:02 mdcass

I noticed that https://github.com/turbolinks/turbolinks is no longer under active development. Would that be a problem since Orchid relies on it?

bilogic avatar Jul 04 '21 13:07 bilogic