Back button

If open a create or edit page in a new tab/window, the cancel button doesn't work, because history doesn't exist. You can try on filament-demo https://demo.filamentphp.com/shop/customers open a customer in a new tab/window and try to click Cancel button The solution is really simple, add a check to history.length > 1
->alpineClickHandler(
'document.referrer && window.history.length > 1 ? window.history.back() : (window.location.href = ' . Js::from(
$url
) . ')'
)
->alpineClickHandler(
'document.referrer && window.history.length > 1 ? window.history.back() : (window.location.href = ' . Js::from(
$url
) . ')'
)
Is it a bug? --- SPA context In SPA mode, when cancel button is pressed, return to the cached list page It is a problem when a table is filtered by a discriminant field that is modified in edit, when come back to table, the cache prevent to apply right the filter. I know that I can exclude some Resource/url from SPA, but forl all tables is annoying At the moment I make a custom back buttom:
->alpineClickHandler(
Filament::getCurrentPanel()->hasSpaMode() ?
('window.location.href = ' . Js::from($url)) :
(
'document.referrer && window.history.length > 1 ? window.history.back() : (window.location.href = ' . Js::from(
$url
) . ')'
)
)
->alpineClickHandler(
Filament::getCurrentPanel()->hasSpaMode() ?
('window.location.href = ' . Js::from($url)) :
(
'document.referrer && window.history.length > 1 ? window.history.back() : (window.location.href = ' . Js::from(
$url
) . ')'
)
)
Exists others options?
2 Replies
toeknee
toeknee3mo ago
I would say it is a bug. Cancel should take you to the resource list in the native pages.
galli.roberto
galli.robertoOP3mo ago
The unique way that I have found to use back button with SPA is use url instead alpineClickHandler and js history
$url = $this->previousUrl ?? static::getResource()::getUrl();

class BackAction
{
public static function make(string $url): Action
{
return Action::make('back')
->icon('heroicon-o-arrow-left')
->hiddenLabel()
->url($url)
->color('gray');
}
}
$url = $this->previousUrl ?? static::getResource()::getUrl();

class BackAction
{
public static function make(string $url): Action
{
return Action::make('back')
->icon('heroicon-o-arrow-left')
->hiddenLabel()
->url($url)
->color('gray');
}
}

Did you find this page helpful?