This is a migrated thread and some comments may be shown as answers.

Using history.replaceState with kendo ui Router to add new URL parameter

5 Answers 205 Views
SPA
This is a migrated thread and some comments may be shown as answers.
Cedric
Top achievements
Rank 1
Cedric asked on 16 Nov 2016, 11:26 AM

I am using kendo ui router and want to replace a URL parameter on each change of the route. So on the change event of the router I have the following code:

 

window.history.replaceState({}, document.title, getUpdatedUrl())

The parameter I want to add is updated successfully, but when I navigate back or forward the kendo ui router no longer catches these events, and does not navigate to the appropriate view (the page URL changes properly). Any ideas how to fix this?

5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 18 Nov 2016, 09:35 AM

Hello Cedric,

Have you tried to use the window.location to navigate and load a new page? 

Regards,
Boyan Dimitrov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Cedric
Top achievements
Rank 1
answered on 18 Nov 2016, 10:52 AM

Hello Boyan,

Unfortunately this would not work in my case. I do not want to navigate to a new page, but just change the parameter in the URL. The issue I have is that I need the fragment information from the URL to be send to the server (asp mvc) on page refresh, but by default the browsers do not send this information. So I try to manually add it as a parameter, but this does not work when a Router is used. 

Any suggestions?

0
Boyan Dimitrov
Telerik team
answered on 22 Nov 2016, 09:54 AM

Hello Cedric,

The Kendo Router does have its own history. In order to replace the state of a history object the replace method of the Kendo Router should be used to update the router history. Please refer to the http://dojo.telerik.com/edeMa/2 example. 

Regards,
Boyan Dimitrov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
0
Cedric
Top achievements
Rank 1
answered on 25 Nov 2016, 02:53 PM

Sadly this does not work for me. What I need is to replace the current url, e.g.  www.somepage.sth?param=1#/foo, with another one which has one additional parameter -  www.somepage.sth?param=1&newParam=foo#/foo

The router.replace function "normalizes" the string to only get the fragment, so in practice it will just replace the fragment part (i.e. #/foo).

What I want to do is to pass the fragment part of the url (#/foo) to the server on page refresh, but only parameters are passed to the server (running asp mvc), so on each change of the router I want to add the information as parameter, I can change the url with history.replaceState, but the router navigation does not work properly after that.

0
Boyan Dimitrov
Telerik team
answered on 29 Nov 2016, 05:49 PM

Hello Cedric,

I am sorry to hear that the replace method of the router does not work for your case. 

The only solution left is to enable the pushState option of the Kendo UI Router. When it is enabled the router will use the history pushState API. Unfortunately as stated in the article the history pushState API currently has limited support across current browsers.

Regards,
Boyan Dimitrov
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
SPA
Asked by
Cedric
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Cedric
Top achievements
Rank 1
Share this question
or