Reputation: 143
I m trying to acces the create page from the navbar when i m under the home page i can access to the url without problem ('http://todolist.test/todo/create') but when i try to acces from the show page the url have a duplication ('http://todolist.test/todo/todo/create') "todo" repeated 2 times in url .
<ul class="navbar-nav mr-auto">
<li class="{{Request::is('/')? 'active' : ''}}">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="{{Request::is('todo/create')? 'active' : ''}}">
<a class="nav-link" href="todo/create">Create Todo</a>
</li>
</ul>
create page route Method :GET|HEAD | URI :todo/create | Name :todo.create | Action: App\Http\Controllers\TodosController@create |Middleware: web show page route Method:GET|HEAD | URI:todo/{todo} | Name:todo.show |Action: App\Http\Controllers\TodosController@show | Middleware:web
Upvotes: 1
Views: 1569
Reputation: 3805
I would just add a leading / to your url:
<a class="nav-link" href="/todo/create">Create Todo</a>
Upvotes: 3
Reputation: 1696
A link reference like href="todo/create"
adds these words to your current url(in address bar), if the page you are on is http://yourdomain.com/ , it refers to http://yourdomain.com/todo/create
If you are then using the same code to create the link, and you click it again( assuming it is in your header or statically implemented on the page) it will direct to http://yourdomain.com/todo/create/todo/create
Therefor i strongly advice to take the dynamic approch with using a function to 'generate' your url( based on your host settings).
asset('your/extension/goes/here')
is a function supplied by laravel, and it does just that: generate your base_url.
If the href="todo/create"
receives a url starting with a protocol(like http
and https
, it wil not add the string to the url, but call it directly.
So using href="{{ asset('todo/create') }}"
will render into href="http://yourdomain.com/todo/create"
in every situation, thereby fixing your issue :).
Upvotes: 0