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

feat(menu): add support for query parameters (#283) #324

Merged
merged 3 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions e2e/menu.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,18 @@ describe('nb-menu', () => {
expect(browser.getCurrentUrl()).toContain('#/menu/1');
});
});

it('should add query string to url', () => {
element.all(menu1).first().click()
.then(() => {
expect(browser.getCurrentUrl()).toContain('param=1');
})
});

it('should add query string to url (navigate home)', () => {
element(homeButton).click()
.then(() => {
expect(browser.getCurrentUrl()).toContain('param=2');
})
});
});
2 changes: 2 additions & 0 deletions src/app/menu-test/menu-test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class NbMenuTestComponent implements OnInit, OnDestroy {
title: 'Menu #1',
link: '/menu/1',
icon: 'nb-keypad',
queryParams: { param: 1 },
},
{
title: 'Menu #2',
Expand Down Expand Up @@ -166,6 +167,7 @@ export class NbMenuTestComponent implements OnInit, OnDestroy {
{
title: 'Menu #3.3.2',
link: '/menu/3/3/2',
queryParams: { param: 2 },
home: true,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<a *ngIf="menuItem.link && !menuItem.url && !menuItem.children && !menuItem.group && !menuItem.hidden"
[routerLink]="menuItem.link"
[fragment]="menuItem.fragment"
[queryParams]="menuItem.queryParams"
[attr.target]="menuItem.target"
[attr.title]="menuItem.title"
[class.active]="menuItem.selected"
Expand Down
2 changes: 1 addition & 1 deletion src/framework/theme/components/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class NbMenuComponent implements OnInit, AfterViewInit, OnDestroy {

if (homeItem) {
if (homeItem.link) {
this.router.navigate([homeItem.link]);
this.router.navigate([homeItem.link], { queryParams: homeItem.queryParams });
}

if (homeItem.url) {
Expand Down
5 changes: 5 additions & 0 deletions src/framework/theme/components/menu/menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { share } from 'rxjs/operators/share';
import { Params } from '@angular/router';

export interface NbMenuBag { tag: string; item: NbMenuItem }

Expand Down Expand Up @@ -87,6 +88,10 @@ export abstract class NbMenuItem {
* @type {boolean}
*/
group?: boolean;
/** Map of query parameters
*@type {Params}
*/
queryParams?: Params;
parent?: NbMenuItem;
selected?: boolean;
data?: any;
Expand Down