Gravatar for ncipollina@captechconsulting.com

Question by ncipollina, Aug 1, 2016 3:44 PM

Query adding Slash to Url

We have an interesting issue occurring with our search queries. Whenever we have a search term or apply a facet on our Coveo search page, a forward slash is being appended to the url before the query is applied in the browser. So if I'm searching for the term "car" my url looks like this:

search#/q=car

Instead of what I'd expect this:

search#q=car

The query is working on the search page and everything but if I try to browse to either of those url's, the search page isn't starting with a q=car, but an empty search. We want to be able to build links with prefilled facets and queries, but we are presently unable to do so because of this issue. Any ideas of what might be going on here?

Thanks in advance, Nick

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Aug 1, 2016 4:08 PM

The JS UI is not supposed to add this to the URL. The issue may be in your custom code for your specific implementation.

You could debug in your browser developer tools by adding code like this to your page.

$(window).on("hashchange", function(e){
    debugger;
})​;

It will break every time the hash changes. You will be able to inspect the new hash with e.originalEvent.newURL. When it matches the hash with a slash, check the stack trace to identify where this change comes from.

I hope this helps

Jeff

Gravatar for ncipollina@captechconsulting.com

Comment by ncipollina, Aug 2, 2016 9:13 AM

We have discovered that the issue is ngRoute from Angular. It is appending the / after a # in the url. Are you aware of any other Coveo clients that might also be using Angular? And if so, is there a known work around?

Thanks, Nick

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Aug 2, 2016 1:32 PM

Hi Nick,

We already saw this scenario with Backbone in the Coveo Cloud Administration Console. One of our engineer created a small documentation to change the handling of the Coveo JavaScript Search Framework state to Backbone: https://gist.github.com/wfortin/2a00af8eb1f759ad8bb16bf9fdf9f915

You will need to code something similar for the Angular router. It would be nice if you could share your solution here for other users.

I hope this helps.

Jeff

Gravatar for dan@getfishtank.ca

Answer by Dan Cruickshank, Sep 1, 2016 12:59 PM

We do this - a lot. But we don't use Angular however, we roll our own custom micro-frameworks. But for us the first step is to "Disable History" (Or uncheck Enable History) on the Coveo Search component. That stops it from writing to the hash. Then when do our own reading/writing to hash and update the coveo components from that.

Ask a question