douqufan9148 2019-03-04 16:18
浏览 53
已采纳

如何在laravel 5.8.0中链接菜单页面

I am facing a problem in the menu bar which doesn't show result correctly. I am sharing a few lines.

index.blade.php: -

<nav class="navbar navbar-expand-lg navbar-light">
  <a class="navbar-brand" href="">Easy Service</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav ml-auto">
      <li class="nav-item ">
        <a class="nav-link" href="">Home </a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="about">About</a>
      </li>
        <li class="nav-item">
        <a class="nav-link" href="services">Services</a>
      </li>

      <li class="nav-item">
        <a class="nav-link " href="contact">Contact</a>
      </li>

      <li class="es">
        <a href="#" class="nav-link" data-toggle="modal" data-target="#myModal">Login</a>
      </li>
    </ul>
</nav>

Here is another file.

web.php

<?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('index');
});
Route::get('/about', function () {
    return view('about');
});
Route::get('/contact', function () {
    return view('contact');
});
Route::get('/services', function () {
    return view('services');
});

When I open up the pages from the home page by clicking the links, the output is correct but when I open up the links through other pages then home page link is not working. If I put (/index) in web.php file, then it worked, but I don't want to show my home page link in URL with (/index). It is only by opening with showing the name with URL after a slash (/).

How can I link home page without showing URL on the browser?

Home Page with Empty slash Home Page with Empty slash About Page with Non-empty slash About Page with Non-empty slash

  • 写回答

1条回答 默认 最新

  • doutao4480 2019-03-04 16:31
    关注

    don't use empty href attribute in <a> if it should reference to index page use <a href="/"> because when href is not filled link will follow to current page. Or you can use named routes in Laravel https://laravel.com/docs/5.8/urls#urls-for-named-routes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀