简体   繁体   English

如何从组件过渡到余烬中的路线

[英]How to transit from a component to a route in ember

I have a popup component in which i have a button and on click of that if im in my target route (mainRoute) i just want to pass the query parameters to my current route, but if i'm in another route i just want to transit with new query parameters. 我有一个弹出组件,其中有一个按钮,如果我在目标路由(mainRoute)中单击该按钮,则只想将查询参数传递给当前路由,但是如果我在另一条路由中,我只想使用新的查询参数进行传递。 I know neither transitionTo or transitionToroute work. 我不知道transitionTo或transitionToroute都工作。 Is there any way to do that? 有什么办法吗?

The transitionTo wouldn't work because you don't have access to routing from inside your component context. transitionTo无效,因为您无权从组件上下文内部访问路由。 You can add the routing support at any place in your app using -routing service like so: 您可以使用-routing服务在应用程序的任何位置添加路由支持,如下所示:

export default Ember.Component.extend({
    routing: Ember.inject.service('-routing'),
    someFuncUsingRouting(){
        let routing = this.get('routing');
        routing.transitionTo('some-route');
    }
});

This is my code for logout function that close the session and redirect you to /login route. 这是我的注销功能代码,它关闭会话并将您重定向到/ login路由。

import Ember from 'ember';

export default Ember.Component.extend({
    authManager: Ember.inject.service('session'),
    routing: Ember.inject.service('route'),
    tagName: '',

    actions: {
        invalidateSession() {
            console.log("logout invalidateSession");
            this.get('authManager').invalidate();
            let routing = this.get('routing');
            routing.transitionTo('login');
            }
    }
});

This is working code for: ember-cli: 2.8.0 node: 7.1.0 这是以下代码的工作代码:ember-cli:2.8.0节点:7.1.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM