Get current route name in Ember

前端 未结 10 2112
我在风中等你
我在风中等你 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:56

    I had the same problem for a while. then i started exploring router. It always have a state object which can be obtained from any route using

    var route = this;
    var handlerInfos = route.get("router.router.state.handlerInfos");
    var currRouteHandlerInfo = handlerInfos[handlerInfos.length-1];
    var currRouteName = currRouteHandlerInfo.name; //"home"
    

    that's it. Now you have the current route name!

    if you want the current route params,

    var routerParams = this.get("router.router.state.params");
    var currRouteParams = routerParams[currRouteName]; //{ homeId : "1" }
    

提交回复
热议问题