Dot in the url causing problems


#1

Hi,

 In the ember app which has nested routes, if a dot (".") is present in the dynamic segment url, ember gives a 404 error saying that it cannot retrieve the page.

If the same dynamic segment url does not contain a dot, it works fine…

As of now, it is not reporting any error stack in the console of chrome inspector.

Has anyone faced this sort of issue before? Is there a way to encode the dot part of the url ?

Thanks, Vikas


#2

Hi,

 Any updates on this issue?

Thanks, Vikas


#3

That’s a tricky one. And without modifying Ember, I would do something like this:

App.Router.map(function() {
    this.route('foo', { path: '/:foo_id' });
});

App.FooRoute = Ember.Route.extend({
    model: function(params) {
        var id = params.foo_id.replace(/_/g, '.');
        return this.findModel('foo', id);
    },
    serialize: function(model) {
        return {
            foo_id: model.get('id').replace(/\./g, '_');
        };
    }
});

What I did was replace your . with _ whenever interacting with the URL. The serialize function will make sure it gets converted when it goes into the URL, and the model function will make sure it gets converted back when it comes out of the URL. It’s not the prettiest thing in the world, but if you absolutely have to have dots in your IDs, this is a pretty good solution.


#4

Hi,

Thanks for the suggestion.

It looks like when a . is present in the url, it is not even reaching the model hook of the corresponding route. It just displays a message as "Cannot GET " and no error message is present in the console.

However, when the locationtype property of ember is changed to ‘hash’ instead of ‘history’, this problem is no longer present.

Thanks, Vikas


#5

this sounds like your web server is not serving the page, not a problem with ember itself. You need to debug your web server to ensure it responds correctly when the url has a dot in it. I don’t think that you need @gordon_kristan’s solution - I might be wrong but I’m pretty sure dots work in dynamic segments just fine.


#6

I was using the ember server for serving the pages.

Not sure if this issue is present when it is used with other servers too…


#7

It turns out that it was an issue with the ember cli server.

When the same app was deployed on nodejs server, it served the route with “.” correctly.

-Vikas