SOLVED: Specifying the default template for root route


#1

I have an app for posts and tags. At the moment they don’t have any relations, just in independent state.

I want specify the default template to be postsList and I had in router.js :

Router.route('/', {name: 'postsList'});

But this screws up the routes for tags, so I changed routes.js to look as:

Router.configure({
    layoutTemplate: 'layout',
    loadingTemplate: 'loading',
    waitOn: function () {
        return Meteor.subscribe('posts');
        return Meteor.subscribe('tags');
    }
});

Router.route('/posts', {name: 'postsList'});

Router.route('/posts/:_id', {
    name: 'postPage',
    waitOn: function () {
        return Meteor.subscribe('comments', this.params._id);
    },
    data: function () {
        return Posts.findOne(this.params._id);
    }
});

Router.route('/posts/:_id/edit', {
    name: 'postEdit',
    data: function () {
        return Posts.findOne(this.params._id);
    }
});

Router.route('/submit', {name: 'postSubmit'});

// Tags Start

Router.route('/tags', {name: 'tagsList'});

Router.route('/tags/submit', {name: 'tagSubmit'});

Router.route('/tags/:_id', {
    name: 'tagPage',
    data: function () {
        return Tags.findOne(this.params._id);
    }
});

Router.route('/tags/:_id/edit', {
    name: 'tagEdit',
    data: function () {
        return Tags.findOne(this.params._id);
    }
});

// Tags End


// Authentication

var requireLogin = function () {
    if (!Meteor.user()) {
        if (Meteor.loggingIn()) {
            this.render(this.loadingTemplate);
        } else {
            this.render('accessDenied');
        }
    } else {
        this.next();
    }
};

Router.onBeforeAction(requireLogin, {only: ['postSubmit', 'tagSubmit']});

As a result, when I access to root route of the app, it gives me error:

Oops, looks like there’s no route on the client or the server for url: "http://askar-blog.meteor.com/."

Any solution?

If you’re familiar with Rails you can do in routes.rb:

root 'posts#index'
resources :posts

#2

Solved in StackOverflow http://stackoverflow.com/q/32491786/1745902

Router.route('/', function () {
  this.redirect('/posts');
});

It seems I was asking a trivial question but no one replied here :smile: