douqufan9148
2019-03-04 16:18 阅读 44
已采纳

如何在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 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

    点赞 评论 复制链接分享

相关推荐