spatie / laravel-menu

Html menu generator for Laravel
https://freek.dev/414-a-modern-package-to-generate-html-menus
MIT License
923 stars 82 forks source link

Problem when adding a new item in the menu I get 2 items activated that redirect to another page. #118

Closed alexv96 closed 3 years ago

alexv96 commented 3 years ago

I created a never seen and function as beta, the issue is that in the menu it redirects me to the new page but leaves me selected 2 options instead of only 1. What could it be? or how could I fix it? it only happens with these routes

This is the new view image

And this is the old view

image

As you can see the second image marks 1 option instead the first image leaves me 2 selected menus. Attached code:

    <div id="sidebar-scrollbar">
        <nav class="iq-sidebar-menu">
            @php
            $menu = Menu::new()
            ->addClass('iq-menu')
            ->add(Spatie\Menu\Html::raw('<span>Principal</span></li>')
                ->addParentClass('iq-menu-title')
            )
            ->route('home', '<i class="ri-home-line"></i><span>Dashboard</span>')
                ->addClass('iq-waves-effect')
            @endphp

            @can('view all reports')
                @php
                    $menu->submenu(
                        Spatie\Menu\Link::to('#', '<i class="ri-folder-chart-line"></i><span>Desempeño</span><i class="ri-arrow-right-s-line iq-arrow-right"></i>')
                            ->addClass('iq-waves-effect'),
                        Menu::new()
                            ->addClass('iq-submenu')
                            ->routeIfCan('view all reports', 'report.index', 'Ejecutivos')
                                ->addClass('iq-waves-effect')
                            ->routeIfCan('view all reports', 'report.compareTeams', 'Equipos')
                                ->addClass('iq-waves-effect')
                            ->routeIfCan('view all reports', 'report.conversions', 'Conversion')
                                ->addClass('iq-waves-effect')
                    )
                @endphp
            @endcan
            @php
                $menu->routeIfCan('view calendar', 'calendar', '<i class="ri-calendar-2-line"></i><span>Calendario</span>')
                        ->addClass('iq-waves-effect')
                    ->linkIfCan('view opportunities',route('opportunity.index',['r'=>'1']), '<i class="ri-pencil-ruler-line"></i><span>Oportunidades</span>')
                        ->addClass('iq-waves-effect')

            @endphp
            @can('view all opportunities')
                @php
                     $menu->routeIfCan('view all opportunities','opportunities.new_list', '<i class="ri-pencil-ruler-line"></i><span>Oportunidades</span><small class="badge badge-pill badge-danger float-right font-weight-normal ml-auto">BETA</small>')
                            ->addClass('iq-waves-effect')
                @endphp    
            @endcan
            @php
                $menu->submenu(
                    Spatie\Menu\Link::to('#', '<i class="ri-function-line"></i><span>Clientes</span><i class="ri-arrow-right-s-line iq-arrow-right"></i>')
                        ->addClass('iq-waves-effect'),
                    Menu::new()
                        ->addClass('iq-submenu')
                        ->routeIfCan('view accounts', 'account.index', 'Cuentas')
                        ->routeIfCan('view contacts', 'contact.index', 'Contactos')
                )
            @endphp
            {!! $menu->setActiveFromRequest()->render() !!}
        </nav>
        <div class="p-3"></div>
    </div>

Routes

Route::get('opportunity/beta/index','OpportunityController@new_list')->name('opportunities.new_list'); //It leaves 2 menu options active

Route::get('opportunity','OpportunityController@index')->name('opportunity.index'); //Only activates 1 menu option