Javascript 无法通过url访问余烬子路由并将我重定向到父路由
我想通过url访问子路由,例如:Javascript 无法通过url访问余烬子路由并将我重定向到父路由,javascript,url,ember.js,ember-cli,ember-router,Javascript,Url,Ember.js,Ember Cli,Ember Router,我想通过url访问子路由,例如:https://my-app.com/dashboard/library。当我单击此按钮时,Ember会将我重定向到https://my-app.com/dashboard并正确填充此路线的模型数据,但我想转到https://my-app.com/dashboard/library,及其新型号数据。 另一方面,我可以访问https://my-app.com/login通过url,没有模型数据 在environment.js我有locationType:“auto”
https://my-app.com/dashboard/library
。当我单击此按钮时,Ember会将我重定向到https://my-app.com/dashboard
并正确填充此路线的模型数据,但我想转到https://my-app.com/dashboard/library
,及其新型号数据。
另一方面,我可以访问https://my-app.com/login
通过url,没有模型数据
在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访问此子路由,或者你们中的任何人发生过类似情况?我认为问题出在仪表板上。在
afterModel
挂钩处:
afterModel: function(){
this.transitionTo('dashboard.index'); // needless
}
每次调用
dashboard
路由时,此部件将重定向到dashboard.index
。请记住dashboard.index
是一个与child
和library
相同的子路径,因此您永远无法找到它们。您能分享dashboard和dashboard/library的路径吗?我把它们记下来作为一个答案……您能把它们移到您的问题上吗,然后包括你如何定义你点击的链接?只是想确定你实际上被重定向到一个新的URL。当您嵌套这样的路由时,/dashboard/child将在屏幕上呈现dashbaord的模板,child中的任何内容都将放置在dashboard的{{outlet}}
中。
afterModel: function(){
this.transitionTo('dashboard.index'); // needless
}