Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (53 sloc) 1.58 KB

Short code snippets teaching you how to do various things in Vulcan.

Using Router Hooks

The router exposes an onUpdate hook that triggers every time the route changes (including when the initial route is triggered).

Here's how you'd use it in conjunction with Apollo's imperative API to check if the current user has completed their profile:

import { addCallback, getFragment } from 'meteor/vulcan:core';
import Users from 'meteor/vulcan:users';
import gql from 'graphql-tag';

function checkProfileOnUpdate (unusedItem, store, apolloClient) {
  const query = gql`
    query getCurrentUser {
      currentUser {

  const currentUser = apolloClient.readQuery({query}).currentUser;

  if (currentUser && !Users.hasCompletedProfile(currentUser)) {
    alert(`Current user hasn't completed their profile!`)

addCallback('router.onUpdate', checkProfileOnUpdate);

Load a Random Post

On the server:

const randomResolver = {
  Query: {
    postsRandom(root, args, context) {
      const postCount = context.Posts.find({status: 2}).count();
      return context.Posts.find({status: 2}, {limit: 1, skip: _.random(postCount)}).fetch()[0];

addGraphQLQuery(`postsRandom: Post`);

On the client:

const withRandomPost = graphql(gql`
  query postsRandom {
    postsRandom {

export default withRandomPost(PostsItem);