Kalip
Kalip

Reputation: 106

Meteor Iron Router: How to handle a redirected url with double slash

I have made a redirection from the old website to the new one. The new website is built with Meteor and Iron Router. The redirected url is: https://example.com//redirected-url

As you can see there is a double slash in this url. For some reason I cannot work with the htaccess file of the old website to modify the regex. So my last option is to handle this kind of route with Iron Router.

Do you know how to manage this kind of route with Iron Router ?

Update:

Here a sample of router configuration (all routes follow the same config):


Router.configure({
  layoutTemplate: "layout",
  loadingTemplate: "loading"
});

Router.map(function () {
  this.route("route-name", {
    path:"/",
    template:"template-name",
    waitOn: function () {
        return Meteor.subscribe("list");
    }
});

// catch all route for unhandled routes 
this.route("notfound", {
  path:"*"
});

Thanks in advance.

Upvotes: 2

Views: 564

Answers (3)

Feras Alkhouri
Feras Alkhouri

Reputation: 349

I know this is an old post, but in case someone encounters same issue.

I had same problem, The fix was to figure out why the double slash was there!

And the reason was: When I sat up the redirect url, I had an extra slash at the end of the redirect url. e.g: http://www.something.com/ I changed this to http://www.something.com and then got no more problems.

Upvotes: 0

ncubica
ncubica

Reputation: 8475

I did almost the same as @Carl B. Suggested, but instead or use Router.go("Home") which I dont know why didnt worked for me I used location.href javascript method.

Meteor.startup(function () {
    Template.Home.rendered = function(){
        if(window.location.pathname === "//"){
            location.href = "/";
        }
    }
}

Upvotes: 0

Kalip
Kalip

Reputation: 106

I am not sure it was the right thing to do, but it worked.

Template.mainTemplate.rendered = function() {
    if(
        window.location.pathname === "//url-example-1"
        || window.location.pathname === "//url-example-2"
        || window.location.pathname === "//url-etc"  
    ){  Router.go("home")  }
};

Upvotes: 1

Related Questions