Scalahansolo
Scalahansolo

Reputation: 3015

Iron router data not found not working properly

I have the following code in my router file.

Router.onBeforeAction(mustBeSignedIn, {except: ['home', 'tests']})
Router.onBeforeAction('dataNotFound')
Router.onBeforeAction('loading')

Router.configure ->
  loadingTemplate: 'loading'
  notFoundTemplate: '404'


#define routes
Router.map ->

  @route 'chat',
    path: '/chat/:room_name'
    waitOn: ->
      [Meteor.subscribe('rooms'),
      Meteor.subscribe('users'),
      Meteor.subscribe('bookmarks', @params.room_name),
      Meteor.subscribe('notifications'),
      Meteor.subscribe('usersNoteCount'),
      Meteor.subscribe('system_messages', @params.room_name)]
    data: ->
      Rooms.findOne({room_name: @params.room_name})

And whenever I run into the case where a specific room doesn't exist, the page still tries to render the chat page when the data is null or undefined.

I am not sure how to go about fixing this as everything I have read tells me this is the exact way to handle a not found page.

EDIT

With the above code edit, I am still having an issue where I am either loading forever, or I get rid of the two subscriptions that require a parameter, I am seeing a blank page on load. What am I doing wrong here?

The loading forever issue I feel I need to fix on the publish side, but I am still not entirely sure how to fix it.

Upvotes: 0

Views: 673

Answers (2)

Peppe L-G
Peppe L-G

Reputation: 8345

Seems like it doesn't work properly at the moment.

https://github.com/EventedMind/iron-router/issues/745

Upvotes: 1

David Weldon
David Weldon

Reputation: 64312

As suggested in the docs, you need to add Router.onBeforeAction('dataNotFound'). Give that a try and let me know how it goes.

Upvotes: 1

Related Questions