Laravel PHP, navbar "not active"



我的一个laravel(php框架(项目中的导航栏突然停止工作,我想我已经尝试了所有的方法,但都不起作用,也没有让我回到它的工作点,有什么解决方案或建议如何解决这个问题?导航栏

<div class="container mx-auto flex justify-between p-4">
<h1 class="text-xl font-black">stackoverflow</h1>
<nav class="navbar navbar-inverse navbar-fixed-top">
<a href="{{ route('home') }}" class="text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>
<a href="{{ route('about') }}" class="text-lg mx-2 text-white hover:text-black transition">About</a>
</nav>
</div>

web.php

Route::get('/', function () {
return view('index');
})->name('home');
Route::get('/about', function () {
return view('about');
})->name('about');

默认

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>sss</title>
<link rel="stylesheet" href="{{ asset('css/app.css')}}">
</head>
<body class='bg-sky-500 text-white'>
<header class="fixed bg-sky-400 top-0 left-0 right-0" z-50>
<div class="container mx-auto flex justify-between p-4">
<h1 class="text-xl font-black">ssss</h1>
<nav class="navbar navbar-inverse navbar-fixed-top">
<a href="{{ route('home') }}" class="text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>
<a href="{{ route('about') }}" class="text-lg mx-2 text-white hover:text-black transition">About</a>
</nav>
</div>
</header>
<main>
@yield('page-content')
</main>
<footer>
<div class="container mx-auto p4">
<p>&copy; 
<a>ssss</a>
<a href="{{ url('ssss') }}"class="bg-color-pink-500 text-center py-2 px-4 rounded hover:bg-purple-500 transition">sss</a> 
<a href="{{ url('ssss') }}"class="bg-color-pink-500 text-center py-2 px-4 rounded hover:bg-purple-500 transition">ssss</a>
</p>

</div>
</footer>
</body>
</html>

编辑:https://github.com/wsamselbaudat/LaravelProject资源/视图/2个blade.php文件(忽略dashborad(,在about页面上,导航栏工作得很好,我希望导航栏在index.blade.php 上工作

您可以使用request((helper is((方法检查当前url或者可以使用request((获取当前url->url((方法,并将其与链接路由url 进行比较

试试这个

<a href="{{ route('home') }}" class="@if(request()->is('/')) your-active-class @endif text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>
<a href="{{ route('home') }}" class="@if(request()->is('/about')) your-active-class @endif text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>

<a href="{{ route('home') }}" class="@if(request()->url()==route('home')) your-active-class @endif text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>
<a href="{{ route('home') }}" class="@if(request()->url()==route('about')) your-active-class @endif text-lg mx-2 text-white hover:text-pink-500 transition">Home</a>

最新更新