无法通过网址访问Ember子路由,并将我重定向到父路由

时间:2019-03-08 13:07:43

标签: javascript url ember.js ember-cli ember-router

我想通过 url 访问子路线,例如:DbContextOptionsBuilder。当我单击此按钮时,Ember将我重定向到https://my-app.com/dashboard/library并正确填充此路线的模型数据,但我想使用新模型数据转到https://my-app.com/dashboard。 另一方面,我可以通过网址访问https://my-app.com/dashboard/library,但没有模型数据。

https://my-app.com/login,我有environment.js,而我的locationType: "auto"就像:

router.js

我的路线:

Router.map(function() {
  this.route('login');
  this.route('dashboard', function() {
    this.route('child', {path: '/child/:child_id'});
    this.route('library');
  });
});

还有

// Route: dashboard
import Ember from 'ember';
import RouteHistoryMixin from 'ember-route-history/mixins/routes/route-history';

export default Ember.Route.extend(RouteHistoryMixin, {
    model: function() {
        let userId = this.authentication.getPlayerId();
        let actions =  this.store.findAll('action');
        return Ember.RSVP.hash({
            actions: actions,
            tasks: Ember.RSVP.all([actions]).then((actions) => {
                return this.store.findAll('task')
            }),
            rank: this.store.findAll('rank')
        });
    },
    afterModel: function(){
        this.transitionTo('dashboard.index');   // needless
    },
    setupController(controller, model) {
        this._super(...arguments);
        Ember.set(controller, 'tasks', model.tasks);
        Ember.set(controller, 'rank', model.rank);
    }
    // . . .

可能是配置标志或路由器配置问题?

我该如何通过url访问此子路由,或者您中的任何人遇到了类似的情况?

1 个答案:

答案 0 :(得分:1)

我认为问题出在仪表板上。在afterModel钩子处:

afterModel: function(){
    this.transitionTo('dashboard.index');   // needless
}

每次调用dashboard.index路由时,此部分都会重定向到dashboard。请记住,dashboard.index是与childlibrary相同的子路线,因此您永远都不会到达它们。

相关问题