Iron Router: Handle canonical tag

Hey guys,
I’m trying to add the canonical tag to my application, because I want to prevent duplicate content on Google. I’m using Iron Router for routing and also the tap18n router plugin to serve international versions of my app (f.e.,,.…). Now I’m running into the following problem:

On “” or “” I’ll get duplicate content on both sites - but both urls are different (with and without last slash). Here I need to set the canonical to tell Google that only one url should be listed. What would be the easiest solution for this? My current definition looks like this:

Router.route('/', {
fastRender: true,

onBeforeAction: function () {
        title: TAPi18n.__("seo_title"),
        meta: {
            'description': TAPi18n.__("seo_meta")

    var router = Router.routes["start"];
    DocHead.addLink({rel:'alternate',hreflang:'x-default', href:''+router.path(null,{lang:'en'})});
    DocHead.addLink({rel:'alternate',hreflang:'de', href:''+router.path(null,{lang:'de'})});
    DocHead.addLink({rel:'alternate',hreflang:'es', href:''+router.path(null,{lang:'es'})});

    //Here we set the canonical, but this isn't safe
    DocHead.addLink({rel:'canonical', href:''+router.path(this)});;

onAfterAction: function()
    Meteor.isReadyForSpiderable = true;



This solution isn’t safe because it sets the current url as canonical. The problem here is the internationalization, so for my route “start” there are 5 combinations available ("/",/de","/es","/de/","/es/"). In my case I want to set “/”,"/de", “/es” as canonical.

Hm, I’ve not used iron router for a long time now, but here’s what I think you could try:

on your onbeforeaction, check the current url and if there is a trailing slash at the end, issue a redirect to the same url without that trailing slash, or vice versa depending on your preference.

this way, the anlytics events won’t have run untl the “correct form” has hit.

1 Like