Skip to content

Commit

Permalink
feat(menu): add support for query parameters (#283) (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishkolesnikov authored and nnixaa committed Mar 27, 2018
1 parent db940b7 commit bbd86aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
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 @@ -293,7 +293,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

0 comments on commit bbd86aa

Please sign in to comment.