Drawer selected item is not changed on browser back and forward buttons

2 Answers 889 Views
Drawer
Stefan
Top achievements
Rank 1
Iron
Stefan asked on 03 Mar 2022, 05:34 PM

Hi,

I have implemented a drawer with a router-outlet inside and when I click on the back or forward buttons in the browser the route changes but the selected item in the drawer stays the same.

Furthermore, I have seen that the same issue is presented in the example in the documentation.

https://www.telerik.com/kendo-angular-ui/components/layout/drawer/routing/

Regards

2 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 08 Mar 2022, 10:13 AM

Hello Stefan,

I tried to reproduce the problem in question in the documentation examples, but to no avail. Something that needs to be clarified is that the demos are loaded in separate iframes, so in order to test this behaviour in a relevant way, one needs to go back/forward in the iframe itself or open the example in a new page.

With that being said, in order to assist further with the current problem, please send us small runnable example (e.g. in Stackblitz) or modify one of the existing ones in the documentation, in order to demonstrate the issue. This will allow us to pinpoint the exact reason for the false behavior.

I am looking forward to hearing from you.

Regards,
Dimiter Madjarov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Stefan
Top achievements
Rank 1
Iron
answered on 09 Mar 2022, 03:02 PM

Hi Dimiter,

Here is a fork of the example you have on https://www.telerik.com/kendo-angular-ui/components/layout/drawer/routing/ :

https://stackblitz.com/edit/angular-g9bs87?file=app/app.component.ts

Moreover, here is an example of my code :

https://stackblitz.com/edit/angular-mfcgek?file=app%2Fapp.component.ts

Namely, if you go to about, then products then click on back button you will notice that the page changes but the menu selected item stays on the default one (Home)  which is selected on init.

If I do not select any item on init then none of them is selected.

Additionally, I have noticed that locally on my computer for the same example the behavior is different in a way that the browser does not refresh the page, however in that case the page and route change but the item selected stays to the last selected one.

Best Regards,

Martin Bechev
Telerik team
commented on 14 Mar 2022, 11:40 AM

Hi Stefan,

Thank you for the provided additional details for this case.

Indeed the selected Drawer item depends on the selected property of the DrawerItem object. In order to highlight the respective item, the Drawer collection needs to be updated on each route change. Please keep in mind that any logic related to the routing is considered developer effort.

Here is the updated demo where the selected item is updated:

https://stackblitz.com/edit/angular-mfcgek-crwubn?file=app%2Fapp.component.ts

I hope this sheds some light on this case.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Stefan
Top achievements
Rank 1
Iron
commented on 14 Mar 2022, 12:54 PM

Hi Martin,

I have checked the example you have sent but the item is still not properly selected. As I can see the route does not have the url and sets it to home again.

Regards,

Stefan

Martin Bechev
Telerik team
commented on 17 Mar 2022, 09:20 AM

Hi Stefan,

Thank you for the provided screenshot.

The reported behavior is caused as the app base href is set to window.location.pathname in app.module file:

 providers: [
      {
        provide: APP_BASE_HREF,
        useValue: window.location.pathname
      }
    ]
Omit these lines of code in order to go to the desired route when changing the url manually:
Regards,
Martin
Adam
Top achievements
Rank 1
commented on 27 Jul 2023, 11:07 AM | edited

In case this is helpful for anyone else - setting the items property to a new array (i.e. this.items = [...this.items]) to trigger change detection is key here.  If you just update the selected value within the array, it will not re-render.
huib
Top achievements
Rank 1
commented on 06 Aug 2024, 02:29 AM

saved my day.. should this go into the docs?
Tags
Drawer
Asked by
Stefan
Top achievements
Rank 1
Iron
Answers by
Dimiter Madjarov
Telerik team
Stefan
Top achievements
Rank 1
Iron
Share this question
or