ms-seo icon indicating copy to clipboard operation
ms-seo copied to clipboard

fix Router.current().route for NotFound route

Open for2ne opened this issue 10 years ago • 7 comments

#56 and etc.

Fix bug "TypeError: Cannot read property 'getName' of undefined" for "NotFound" route

for2ne avatar Jun 09 '15 21:06 for2ne

@DerMambo please merge at your earliest convenience :)

petermikitsh avatar Jul 14 '15 15:07 petermikitsh

@for2ne please consider @lhristov comment in order to merge this. Thanks!

fentas avatar Nov 27 '15 19:11 fentas

@lhristov no. Error is disappear with OR only. was tested :) @fentas no problems

for2ne avatar Nov 28 '15 18:11 for2ne

http://js2.coffee/ gives me:

return unless router or router.route

becomes

if (!(router || router.route)) {
  return;
}

@for2ne Strange. This meens if router is undefined/false it checks router.route (which is then undefined.route >> error should be thrown). With and (if (!(router && router.route))) router.route will be checked if route is not undefined/false. I would say and should be the right one.

Or do I miss something? Hm. If return unless router or router.route would become if (!router || !router.route) then it would be right.

fentas avatar Nov 28 '15 19:11 fentas

@fentas you are absolutely right, my bad. I am not good in cofeescript. Error disappeared, but the function probably will return a wrong result...

for good, function getCurrentRouteName should look like this:

getCurrentRouteName = function() {
  var router = Router.current();

  if (router && router.route) {
    return router.route.getName();
  }

  return;
};

for2ne avatar Nov 28 '15 22:11 for2ne

@for2ne right.

getCurrentRouteName = ->
  router = Router.current()
  return router.route.getName() if router and router.route

becomes

getCurrentRouteName = function() {
  var router;
  router = Router.current();
  if (router && router.route) {
    return router.route.getName();
  }
};

This should be sufficient. It does not matter if you do a return in the end. With or without both becomes undefined as return value.

fentas avatar Nov 29 '15 11:11 fentas

The author should give write access to someone...

micktaiwan avatar Jan 13 '18 09:01 micktaiwan