Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Active' Class on Navbar Links #304

Closed
silverskymedia opened this issue Dec 9, 2015 · 9 comments
Closed

'Active' Class on Navbar Links #304

silverskymedia opened this issue Dec 9, 2015 · 9 comments

Comments

@silverskymedia
Copy link

I am creating a Navbar. It creates it fine, but it's not applying the "active" class. From I understood it should do it automatically. Am I wrong? Thanks.

@silverskymedia silverskymedia changed the title Active Links 'Active' Class on Navbar Links Dec 9, 2015
@PatrickRose
Copy link
Collaborator

Hi

Can you give me a snippet?

@silverskymedia
Copy link
Author

Here is a simple snippet of what I’m trying.

{!!
Navbar::withBrand(‘Brand' , '/')
->withContent(Navigation::links([
[
'link' => '/',
'title' => 'Home'
],
[
'link' => 'about',
'title' => 'About Us'
]

        ]))
!!} 

Thanks.

On Dec 9, 2015, at 5:09 AM, Patrick Rose notifications@github.com wrote:

Hi

Can you give me a snippet?


Reply to this email directly or view it on GitHub #304 (comment).

@PatrickRose
Copy link
Collaborator

You need to use route('foo') instead - we do a full match for the active links.

@silverskymedia
Copy link
Author

Thanks for your help. I’m not sure what you mean by “instead.” What does route(‘foo’) replace?

Thanks.

On Dec 10, 2015, at 6:28 AM, Patrick Rose notifications@github.com wrote:

You need to use route('foo') instead - we do a full match for the active links.


Reply to this email directly or view it on GitHub #304 (comment).

@PatrickRose
Copy link
Collaborator

Replace 'link' => 'about' with 'link' => route('about').

If you take a look at Bootstrapper\Navigation you'll see we do $this->url->current() == $item['link']. If you just use 'link' => 'about' then $this->url->current() will return something like http://your.dev.site/about which won't equal about.

route('about') will include the http://your.dev.site/ cruft which will make that check return true.

@silverskymedia
Copy link
Author

I tried that, it doesn’t work for me. It tells me that my route is not defined. Here is how I defined my route:

Route::get('about', 'PagesController@about’);

Is this not correct?

Thanks,
Nate

On Dec 10, 2015, at 7:46 AM, Patrick Rose notifications@github.com wrote:

Replace 'link' => 'about' with 'link' => route('about').

If you take a look at Bootstrapper\Navigation https://github.com/patricktalmadge/bootstrapper/blob/master/src/Bootstrapper/Navigation.php#L304-L305 you'll see we do $this->url->current() == $item['link']. If you just use 'link' => 'about' then $this->url->current() will return something like http://your.dev.site/about which won't equal about


Reply to this email directly or view it on GitHub #304 (comment).

@PatrickRose
Copy link
Collaborator

Ah - if you're not using Named Routes then you should be using url('about')

Essentially - the link value must be the absolute URL - not the relative one.

@silverskymedia
Copy link
Author

OK, great, it's working. Thanks for your help. Would you recommend I use a
Named Route?

On Thu, Dec 10, 2015 at 8:28 AM, Patrick Rose notifications@github.com
wrote:

Ah - if you're not using Named Routes
http://laravel.com/docs/5.1/routing#named-routes then you should be
using url('about')


Reply to this email directly or view it on GitHub
#304 (comment)
.

@PatrickRose
Copy link
Collaborator

I find named routes to be much easier to work with, mainly because route('foo') is more readable than url('foo'), but it's your app :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants