Skip to content

Commit 75205e0

Browse files
committed
menu navigation bug fix
Signed-off-by: MarioRadu <magda_marior@yahoo.com>
1 parent 63e697c commit 75205e0

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

config/autoload/navigation.global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'options' => [
1616
'label' => 'Dashboard',
1717
'route' => [
18-
'route_name' => 'app::index-redirect',
18+
'route_name' => 'dashboard::dashboard-view',
1919
],
2020
'icon' => 'c-blue-500 ti-home',
2121
],

src/App/src/Twig/Extension/RouteExtension.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Dot\DependencyInjection\Attribute\Inject;
88
use Mezzio\Helper\UrlHelper;
9+
use Mezzio\Router\RouteResult;
10+
use Psr\Http\Message\UriInterface;
911
use Twig\Extension\AbstractExtension;
1012
use Twig\TwigFunction;
1113

@@ -25,22 +27,21 @@ public function getFunctions(): array
2527
];
2628
}
2729

28-
public function getCurrentRoute(): ?string
30+
public function getCurrentRoute(): ?RouteResult
2931
{
30-
return $this->urlHelper->getRequest()?->getUri()?->getPath();
32+
return $this->urlHelper->getRouteResult();
3133
}
3234

33-
public function isRoute(?string $route): bool
35+
public function isRoute(?string $routeName): bool
3436
{
35-
if (null === $route) {
37+
if (null === $routeName) {
3638
return false;
3739
}
3840

39-
$currentRoute = $this->getCurrentRoute();
40-
if (null === $currentRoute) {
41+
if (null === $this->getCurrentRoute()) {
4142
return false;
4243
}
4344

44-
return $currentRoute === $route;
45+
return $this->getCurrentRoute()->getMatchedRouteName() === $routeName;
4546
}
4647
}

src/App/templates/partial/menu.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{% for page in container %}
66
{% if navigation.isAllowed(page) %}
77
{% if page.hasChildren() %}
8-
<li class="nav-item dropdown nav-group {% if loop.first %} mT-30 {% endif %} {% if isRoute(page.getOption('uri')) %} open {% endif %}">
8+
<li class="nav-item dropdown nav-group {% if loop.first %} mT-30 {% endif %} {% if isRoute(page.getOption('route')['route_name'] ?? '') %} open current-route {% endif %}">
99
<a class="dropdown-toggle cur-p" {% autoescape false %}{{ pageAttributes(page) ~ extraAttributes }}{% endautoescape %}>
1010
<span class="icon-holder">
1111
<i class="{{ page.getOption('icon') }}"></i>
@@ -23,13 +23,13 @@
2323
{% else %}
2424
{% if page.hasParent() %}
2525
<li class="nav-item dropdown">
26-
<a href="{{ navigation.getHref(page) }}" class="{% if isRoute(page.getOption('uri')) %} text-primary fw-medium current-route {% endif %} {% autoescape false %}{{ pageAttributes(page) ~ extraAttributes }}{% endautoescape %}">
26+
<a href="{{ navigation.getHref(page) }}" class="{% if isRoute(page.getOption('route')['route_name'] ?? '') %} text-primary fw-medium current-route {% endif %} {% autoescape false %}{{ pageAttributes(page) ~ extraAttributes }}{% endautoescape %}">
2727
<span>{{ page.getOption('label') }}</span>
2828
</a>
2929
</li>
3030
{% else %}
3131
<li class="nav-item {% if loop.first %} mT-30 {% endif %}">
32-
<a class="sidebar-link {% if isRoute(page.getOption('uri')) %} text-primary fw-medium current-route {% endif %}" href="{{ navigation.getHref(page) }}" {% autoescape false %}{{ pageAttributes(page) ~ extraAttributes }}{% endautoescape %}>
32+
<a class="sidebar-link {% if isRoute(page.getOption('route')['route_name'] ?? '') %} text-primary fw-medium current-route {% endif %}" href="{{ navigation.getHref(page) }}" {% autoescape false %}{{ pageAttributes(page) ~ extraAttributes }}{% endautoescape %}>
3333
<span class="icon-holder">
3434
<i class="{{ page.getOption('icon') }}"></i>
3535
</span>

0 commit comments

Comments
 (0)