猿问

在 Laravel 中活跃的动态 li 类

这是我的路线


<?php


/*

|--------------------------------------------------------------------------

| Web Routes

|--------------------------------------------------------------------------

|

| Here is where you can register web routes for your application. These

| routes are loaded by the RouteServiceProvider within a group which

| contains the "web" middleware group. Now create something great!

|

*/


Route::get('/', function () {

    return view('welcome');

});


Route::get('/account', 'AccountController@index')->name('account.index')->middleware('auth');

Route::get('/dashboard', 'DashboardController@index')->name('dashboard.show')->middleware('auth');


在我的仪表板上



<div class="main-menu-content">

        <ul class="navigation navigation-main" id="main-menu-navigation" data-menu="menu-navigation">

          <li {{ request()->route()->getName() === 'dashboard.index' ? ' class=active' : '' }}><a href="/dashboard"><i class="ft-home"></i><span class="menu-title" data-i18n="">Dashboard</span></a>

          </li>

          <li {{ request()->route()->getName() === 'account.index' ? ' class=active' : '' }}><a href="/account"><i class="ft-user"></i><span class="menu-title" data-i18n="">Account</span></a>

          </li>

        </ul>

      </div>


我在这里要做的是使li课程处于活动状态,但是我尝试了上面的代码,尽管我在仪表板上但没有活动课程,而且我还检查了我在帐户中时li仍然没有突出显示为活动的。有人可以告诉我有什么问题吗?


汪汪一只猫
浏览 137回答 2
2回答

守着一只汪

您没有命名帐户路由,因此您必须将帐户路由更改为:Route::get('/account',&nbsp;'AccountController@index')->name('account.index')->middleware('auth');您确实将仪表板路由命名为dashboard.show,因此li仪表板的标签必须等于dashboard.show而不是dashboard.index

婷婷同学_

<li&nbsp;class="@if(Route::currentRouteName()&nbsp;==&nbsp;'dashboard.show'&nbsp;active&nbsp;@endif"><a&nbsp;href="/dashboard"><i&nbsp;class="ft-home"></i><span&nbsp;class="menu-title"&nbsp;data-i18n="">Dashboard</span></a>
随时随地看视频慕课网APP
我要回答