Get current route name in Ember

前端 未结 10 2108
我在风中等你
我在风中等你 2020-11-30 05:20

I need to get the current route name in my ember application; I tried this: Ember App.Router.router.currentState undefined but it doesn\'t work for me (there is probablig so

10条回答
  •  离开以前
    2020-11-30 05:45

    The Ember namespace API now has a getOwner method, which is very useful for looking up the currentRouteName, or, other route properties.

      const owner        = Ember.getOwner(this);
      const currentRoute = owner.lookup('router:main').currentRouteName;
      const routeInfo    = owner.lookup(`route:${currentRoute}`).get('info');
      // etc.
    

    I've created an Ember Twiddle example to demonstrate. Use the text input above the "Output" pane to hit other routes like /blue, /green, or /red.

提交回复
热议问题