When the name changes my (slugged) route url is notFound?


I like not having Save buttons.

Say I have a template called “editOne” and the route is /thing/:slug (based on the name). When the name changes on this totally amazing reactive page without a save button then my current url becomes invalid - the router fires and I get a 404 until I can refresh with the new slug.


Name of my thing is “Thing One”

Edit it at http://localhost:3000/things/thing-one

Name of thing is changed to Thing Two - it recalculates the slug and then

localhost:3000/things/thing-one - 404 - Not found. ('Kay - tis correct but I wish you’d redirected me).

Is there a canonical way fo doing this (a redirect) or a more elegant way of avoiding it? What is this problem usually called?

Any help greatly appreciated (preferrably not coffee as it makes my eyes bleed),


I would probably keep lastslug and if router cant find page it will check if it matches lastslug, if yes then router.go to new slug of the document which matched lastslug?


Thanks shock. If it was kept in a session variable we could get into a reactive loop?

What I do now is:

  "change #thing-name": function(event, template) {
    var new_name = template.find("#thing-name").value
    var new_slug = slugify(template.find("#thing-name").value)
   Things.update({_id:this._id}, {$set:{ "name":new_name
                                         , "slug":new_slug }})
   Router.go("editOne", {slug: new_slug});                                          

…and so on

It works okay but for some reason the Router call on the client gives me the heebeegeebees. This may all go away when I put in proper controllers.

Thanks for your help!


I would probably do the switch in route itself, cause now you in async change the slug and async call router.go.
So when router is switching you dont know if new slug is set.
And also when slug is set, it invalidate route, try to switch to 404 and than u call router.go.
Just async hell.

Thats why I would wait in route for collection update and switch clean way there.