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

Cannot Access Ember child route via url and redirects me to the parent route

我想通过 url 访问子路由,例如:https://my-app.com/dashboard/library。当我单击此按钮时,Ember 将我重定向到 https://my-app.com/dashboard 并正确填充此路线的模型数据,但我想使用其新模型数据转到 https://my-app.com/dashboard/library。 另一方面,我可以通过 url 访问 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);
    }
    // . . .

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

export default Route.extend(RouteHistoryMixin, {
    complete: Ember.inject.service(),
    queryParams: {
        taskId: {}
    },
    model(params) {
        if(params.taskId) {
            return Ember.RSVP.hash({
                article: this.store.query('article', { filter: '{"inSyllabus": true}'}),
                task: this.store.query('task', { filter: '{"id": ' + params.taskId + '}'})
            });
        }
        else {
            return Ember.RSVP.hash({
                article: this.store.query('article', { filter: '{"inSyllabus": true}'})
            });
        }
    },
    setupController(controller) {
        this._super(...arguments);
        if (controller.taskId)
            this.store.findRecord('task', controller.taskId).then((task) => {
                controller.set('libraryQueryParam', task.points);
                // Notify Task completion
                let payload = {
                    startDate: new Date(),
                    endDate: new Date(),
                    points: task.points,
                    entries: 1
                };
                // PUT HTTP COMMAND FOR PLAYER
                let playerTask = this.store.createRecord('playTaskTest', payload);
                playerTask.save();
            });
    }
    // . . .

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

我如何通过 url 访问此子路由或者你们中有人发生过类似的事情吗?

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

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

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