滚动导航栏在 Laravel 8 中的新文件中无法工作

huangapple go评论51阅读模式
英文:

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

&lt;nav class=&quot;navbar&quot;&gt;
    &lt;div id=&quot;nav-close&quot; class=&quot;fas fa-times&quot;&gt;&lt;/div&gt;
    &lt;a href=&quot;#home&quot;&gt;home&lt;/a&gt;
    &lt;a href=&quot;#idea&quot;&gt;Idea&lt;/a&gt;
    &lt;a href=&quot;#about&quot;&gt;about&lt;/a&gt;
    &lt;a href=&quot;#packages&quot;&gt;packages&lt;/a&gt;
    
&lt;/nav&gt;

and I have include with main.blade.php file like this way

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;{{ str_replace(&#39;_&#39;, &#39;-&#39;, app()-&gt;getLocale()) }}&quot;&gt;
    &lt;head&gt;
@include(&#39;partials._head&#39;)
    &lt;/head&gt;

@include(&#39;partials._nav&#39;)
    &lt;body&gt;
//contains go here
&lt;/body&gt;
&lt;/html&gt;

and extends main blade file with welcome.blade.php as well like this

@extends(&#39;main&#39;)

and route in web.blade.php file

Route::get(&#39;/&#39;, function () {
    return view(&#39;welcome&#39;);
});

now I need create another blade file like city.blade.php and make web file like

Route::get(&#39;/city&#39;, function () {
    return view(&#39;city&#39;);
});

and include nav.blade.php file with city.blade.php file like this

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
@include(&#39;partials._nav&#39;)
&lt;/head&gt;
&lt;body&gt;

// city containt goes here
&lt;/body&gt;
&lt;/html&gt;
   

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

&lt;nav class=&quot;navbar&quot;&gt;
  &lt;div id=&quot;nav-close&quot; class=&quot;fas fa-times&quot;&gt;&lt;/div&gt;
  &lt;a href=&quot;{{ url(&#39;/&#39;) }}#home&quot;&gt;home&lt;/a&gt;
  &lt;a href=&quot;{{ url(&#39;/&#39;) }}#idea&quot;&gt;Idea&lt;/a&gt;
  &lt;a href=&quot;{{ url(&#39;/&#39;) }}#about&quot;&gt;about&lt;/a&gt;
  &lt;a href=&quot;{{ url(&#39;/&#39;) }}#packages&quot;&gt;packages&lt;/a&gt;
  
&lt;/nav&gt;

main.blade.php file could be -

  &lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;{{ str_replace(&#39;_&#39;, &#39;-&#39;, app()-&gt;getLocale()) }}&quot;&gt;
      &lt;head&gt;
  @include(&#39;partials._head&#39;)
      &lt;/head&gt;

  @include(&#39;partials._nav&#39;)
      &lt;body&gt;
        &lt;main&gt;
          // content go here
          @yield(&#39;content&#39;)
        &lt;/main&gt;
  &lt;/body&gt;
  &lt;/html&gt;

welcome.blade.php could be

@extends(&#39;layouts.front&#39;)

@section(&#39;content&#39;)

Welcome content here

@endsection

city.blade.php could be -

@extends(&#39;layouts.front&#39;)

@section(&#39;content&#39;)

City Page content here

@endsection

This way you can create number of pages.

huangapple
  • 本文由 发表于 2023年5月11日 03:11:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221855.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定