【问题标题】:How to get correct links in laravel如何在 laravel 中获取正确的链接
【发布时间】:2018-06-08 07:27:54
【问题描述】:

我将我的 laravel 项目上传到子文件夹,但我的链接出了点问题。现在我的网址是 site.com/laravel
例如:

<a href="/">Index</a>
<a href="/about">About</a>

当我点击索引或关于 - Laravel 将我重定向到 site.com 而不是 site.com/laravel

如何解决这个问题?

【问题讨论】:

  • 您可以定义如下。 索引 关于
  • 设置基本元标记,如下所示:&lt;base href="http://www.example.com/laravel/"&gt;。见link
  • 使用laravel路由功能链接

标签: php laravel url


【解决方案1】:
<a href="{{url('/')}}">Index</a>

【讨论】:

    【解决方案2】:

    如果你的路线命名你可以使用

    <a href="{{route('home')}}">Index</a>
    <a href=""{{route('about')}}">About</a>
    

    否则

    <a href="{{url('/')}}">Index</a>
    <a href="{{url('about')}}">About</a>
    

    【讨论】:

      【解决方案3】:

      你应该使用{{url('/')}}作为索引,使用{{url('/about')}}作为关于。

      用于链接到您的资产文件使用

      {{ asset('path/to/assets/asset.ext') }}
      

      https://laravel.com/docs/5.6/urls

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-08-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-31
        • 1970-01-01
        • 2012-11-14
        相关资源
        最近更新 更多