Skip to content

Backbone navigate - url encode in different language with diacritics #4085

Open
@adyz

Description

@adyz

I have a search form that redirects the user to search/thetermusersearched where thetermusersearched is the exact value he entered. All this with the navigate function provided by Backbone.

This is all fine when I use strings in English (masa de calcat), but when I add diacritics in the input (masă de călcat) I get the route function fired twice.

The problem I have is in Firefox and Safari (the later in Mac and iOS)

I tried using encodeURI and encodeURIComponent when I use the navigate, but no success.


HTML

<div id="view-goes-here">
    <a href="#" data-string="masa de calcat">One alert</a>
    <a href="#" data-string="masă de călcat">Two alerts</a>
</div>

JS

    var R = Backbone.Router.extend({
        routes: {
            'results/:query': 'results'
        },
        results: function(query) {
            alert('Route triggered: ' + decodeURIComponent(query));
        }
    });
    var myR = new R;
    Backbone.history.start();

    $(function(){
      $('a').on('click', function(e){
       e.preventDefault();
       var href = $(this).data('string');
       href = 'results/' + encodeURIComponent(href);
       console.log(href);
       myR.navigate(href, {trigger: true});
      })
    })

See fiddle here: http://jsfiddle.net/adyz/qcged76e/4/

Any thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions