When I visit a page within the backend which does not exist, I get redirected to the frontend 404 page.
However, I would like to create a backend 404 page, where the menu is still shown. Alternatively, I could redirect to the dashboard oage and send an error message.
But I’m a bit lost on how to do this, so any help is welcome.
Thx a lot 
You could make the current back-end user available to the frontend when logged in. This would give you something to hook into.
Just need this code on the frontend’s code section:
$user = BackendAuth::getUser();
if ($user) {
...
}
2 Likes
title = "Page Not Found (404)"
url = "/404"
layout = "full-content"
==
function onStart()
{
$path = Request::path();
$backend = env('BACKEND_URI');
$backendClean = str_replace("/", "", $backend);
if (starts_with($path, $backendClean) && BackendAuth::getUser()) {
Flash::error("Page not found!");
return Cms::redirect($backend);
}
}
==
<center>
<p>We're sorry, but the page you requested cannot be found.</p>
</center>
What do you think? I’m not sure if it’s a good idea to test for BackendAuth and the url this way… but it works.
Suggestions are welcome ^^
This could be another way;
in Plugin.php,
public function boot() {
// Registering an event listener for 'cms.page.beforeDisplay'
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
// Check if the URL is '/404'
if ($url == '/404') {
// Create an instance of the Backend helper class
$helper = new \Backend\Helpers\Backend;
// Get the base URL of the backend area using the helper function
$baseUrl = $helper->baseUrl();
// Check if the current request URI contains the backend base URL
if (str_contains($_SERVER["REQUEST_URI"], $baseUrl)) {
// Redirect to the backend base URL if the current request URI contains it
return \Redirect::to($baseUrl);
}
}
});
}
3 Likes
Definitly a lot better as a solution 
Thanks ^^
2 Likes