Reputation: 12538
I am using blade templating to generate the header on a project I am working on. The header href routes inside the view is as follows:
<a href="index">Home</a>
<a href="about">About</a>
Assuming, no slug is provided in the url, the above href values would work fine. Although, when a slug is provided and the current route is something like:
localhost/www/public/signup/trial
trial
being the slug, then the href ends up generating the following url and throwing an error, when clicking on the anchor:
localhost/www/public/signup/index
Is there any solution that will maintain the correct href linking between views, regardless of whether a slug is provided?
I have been trying to figure this out for a while now and appreciate any advice,
Thanks in advance!
Upvotes: 0
Views: 1714
Reputation: 95
Aside from using the route or url helper, you could also try adding a '/' in front of the route in order to get to the root of the url.
Example:
<a href="/index">Home</a>
<a href="/about">About</a>
Upvotes: 0
Reputation: 9883
You should use the Laravel URL generator to generate links and such, it has some handy features and niceties such as linking to named routes or controller actions.
http://laravel.com/docs/4.2/helpers#urls
The following would link to a route named admin.index
<a href="{{ route('admin.index') }}">Home</a>
The following would link to a route with the controller action of AdminController@index
<a href="{{ action('AdminController@index') }}">Home</a>
You can also specify parameters your route requires too.
action('AdminController@index', [$model->getKey(), 'SomeValue']);
Using the actions or named routes has some extra benefits such as allowing you to update URIs in your application without having to go search through all your view files to update the links, you just need to update your routes.php and everything is handled.
Upvotes: 3
Reputation: 152870
Just use the url()
helper:
<a href="{{ url('index') }}">Home</a>
Upvotes: 1