英文:
scroling navigation bar is not working with new file in Laravel 8
问题
在Laravel 8项目中使用导航栏时,遇到一个问题:在city.blade.php
视图中点击导航栏链接无法正常工作,因为导航页面位于main.blade.php
中。解决方法如下:
将city.blade.php
文件中的导航栏包含部分更改为:
<!DOCTYPE html>
<html lang="en">
<head>
@include('partials._nav')
</head>
<body>
// city content goes here
</body>
</html>
这样,city.blade.php
将包含main.blade.php
中的导航栏,从而解决导航栏在城市视图中不起作用的问题。
英文:
working with Laravel 8 project as well and I have following Navigation bar
<nav class="navbar">
<div id="nav-close" class="fas fa-times"></div>
<a href="#home">home</a>
<a href="#idea">Idea</a>
<a href="#about">about</a>
<a href="#packages">packages</a>
</nav>
and I have include with main.blade.php file like this way
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
@include('partials._head')
</head>
@include('partials._nav')
<body>
//contains go here
</body>
</html>
and extends main
blade file with welcome.blade.php as well like this
@extends('main')
and route in web.blade.php file
Route::get('/', function () {
return view('welcome');
});
now I need create another blade file like city.blade.php and make web file like
Route::get('/city', function () {
return view('city');
});
and include nav.blade.php file with city.blade.php file like this
<!DOCTYPE html>
<html lang="en">
<head>
@include('partials._nav')
</head>
<body>
// city containt goes here
</body>
</html>
but problem is now when I am in city blade view then I click my nav bar link it is not working here. my navigation pages are in main.blade.php so how could I fix this problem?
答案1
得分: 1
Sure, here are the translated parts:
In nav.blade.php
:
<nav class="navbar">
<div id="nav-close" class="fas fa-times"></div>
<a href="{{ url('/') }}#home">home</a>
<a href="{{ url('/') }}#idea">Idea</a>
<a href="{{ url('/') }}#about">about</a>
<a href="{{ url('/') }}#packages">packages</a>
</nav>
In main.blade.php
:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
@include('partials._head')
</head>
@include('partials._nav')
<body>
<main>
// content go here
@yield('content')
</main>
</body>
</html>
In welcome.blade.php
:
@extends('layouts.front')
@section('content')
Welcome content here
@endsection
In city.blade.php
:
@extends('layouts.front')
@section('content')
City Page content here
@endsection
Please note that I've translated the provided code snippets as requested. If you need further assistance or have any questions, feel free to ask.
英文:
nav.blade.php could be
<nav class="navbar">
<div id="nav-close" class="fas fa-times"></div>
<a href="{{ url('/') }}#home">home</a>
<a href="{{ url('/') }}#idea">Idea</a>
<a href="{{ url('/') }}#about">about</a>
<a href="{{ url('/') }}#packages">packages</a>
</nav>
main.blade.php file could be -
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
@include('partials._head')
</head>
@include('partials._nav')
<body>
<main>
// content go here
@yield('content')
</main>
</body>
</html>
welcome.blade.php could be
@extends('layouts.front')
@section('content')
Welcome content here
@endsection
city.blade.php could be -
@extends('layouts.front')
@section('content')
City Page content here
@endsection
This way you can create number of pages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论