Skip to content

Commit

Permalink
Make menu-links absolute (#4008)
Browse files Browse the repository at this point in the history
  • Loading branch information
emptynick committed Mar 20, 2019
1 parent 9428462 commit 1107e32
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/Models/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,19 @@ private static function processItems($items)
// Translate title
$item->title = $item->getTranslatedAttribute('title');
// Resolve URL/Route
$item->href = $item->link();
$item->href = $item->link(true);

if (url($item->href) == url()->current() && $item->href != '') {
if ($item->href == url()->current() && $item->href != '') {
// The current URL is exactly the URL of the menu-item
$item->active = true;
} elseif (starts_with(url()->current(), Str::finish(url($item->href), '/'))) {
} elseif (starts_with(url()->current(), Str::finish($item->href, '/'))) {
// The current URL is "below" the menu-item URL. For example "admin/posts/1/edit" => "admin/posts"
$item->active = true;
}

if (($item->href == '' || url($item->href) == route('voyager.dashboard')) && $item->children->count() > 0) {
if (($item->href == url('') || $item->href == route('voyager.dashboard')) && $item->children->count() > 0) {
// Exclude sub-menus
$item->active = false;
} elseif (url($item->href) == route('voyager.dashboard') && url()->current() != route('voyager.dashboard')) {
} elseif ($item->href == route('voyager.dashboard') && url()->current() != route('voyager.dashboard')) {
// Exclude dashboard
$item->active = false;
}
Expand Down

0 comments on commit 1107e32

Please sign in to comment.