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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题