Ember.js路由:如何设置默认路由立即呈现?

编程入门 行业动态 更新时间:2024-10-28 06:35:45
本文介绍了Ember.js路由:如何设置默认路由立即呈现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我相信,当我深入挖掘时,这将变得清晰,但现在不清楚如何使这一切发生。

我正在关注这个有用的SO文章关于路由,但是从示例中缺少一个重要的部分,即如何让home视图立即呈现,而无需单击home链接?

我已经开始挖掘文档来试图理解这一点,但同样对于后代来说似乎是一个有用的问题。

我一直在玩上述问题的工作jsfiddle示例 here 并与其他示例进行比较,我发现似乎默认路由工作

到目前为止还是一个谜。

当前代码:

App.Router = Em.Router.extend({ enableLogging:true, location:'hash', root:Em.State.extend ({ // EVENTS goHome:Ember.State.transitionTo('home'), viewProfile:Ember.State.transitionTo('profile'), // STATES index:Em.State.extend({ route:/, redirectsTo:'home'}), home:Em.State.extend({ route:'/ home', connectOutlets:function(router,context){ var appController = router.get('applicationController'); appController.connectOutlet('home'); } }), // STATES 个人资料:Em.State.extend({ route:'/ profile', connectOutlets:function(router,context){ var appController = router.get(的ApplicationController); appController.connectOutlet('profile'); } }), doOne:function(){ alert(eins); } })});

更新:解决方案

事实证明,我正在使用的示例不正常的原因是因为它使用 Em.State.extend 而不是 Em.Route.extend 。有趣的部分是,当我逐步改变它们,一个接一个地改变它们的例子,直到我改变了所有这些结果为止,这个例子不起作用。

这里是工作的示例:

App.Router = Em.Router.extend({ enableLogging:true, location:'hash', root:Em。 Route.extend({ // EVENTS goHome:Ember.State.transitionTo('home'), viewProfile:Ember.State.transitionTo('profile'), // STATES index:Em.Route.extend({ route:/, redirectsTo:'home'}), home:Em.Route.extend({ route:'/ home', connectOutlets:function(router,context){ var appController = router.get('applicationController '); appController.connectOutlet({name:'home'}); } }), // STATES 个人资料:Em.Route.extend({ route:'/ profile', connectOutlets:function路由器,上下文){ var appController = router.get('applicationController'); appController.connectOutlet('profile'); } }), doOne:function(){ alert(eins); } })});

解决方案

U可以从索引到家里重定向路线。工作示例: jsfiddle/FRfBt/

I'm sure this will become clear as I dig in deeper, but for now it's not obvious how to make this happen.

I was following the info on this helpful SO article about routing but there is an important piece missing from the example, i.e. how do you get the 'home' view to render right away without having to click the 'home' link?

I've started digging into the docs to try to make sense of this, but meanwhile it seems like a useful question to have answered for posterity.

I've been playing with the working jsfiddle example from the above question here and comparing with this other example I found that seems to have the default routing working

So far it's still a mystery.

Current code:

App.Router = Em.Router.extend({ enableLogging: true, location: 'hash', root: Em.State.extend({ // EVENTS goHome: Ember.State.transitionTo('home'), viewProfile: Ember.State.transitionTo('profile'), // STATES index: Em.State.extend({ route: "/", redirectsTo: 'home' }), home: Em.State.extend({ route: '/home', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet('home'); } }), // STATES profile: Em.State.extend({ route: '/profile', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet('profile'); } }), doOne: function() { alert("eins"); } }) });

UPDATE: Solution

It turns out that the reason the example I was working with was not working was because it was using Em.State.extend rather than Em.Route.extend. The interesting part is that as I step through and change them over one by one the example doesn't work until I change all of them over.

Here is the working example:

App.Router = Em.Router.extend({ enableLogging: true, location: 'hash', root: Em.Route.extend({ // EVENTS goHome: Ember.State.transitionTo('home'), viewProfile: Ember.State.transitionTo('profile'), // STATES index: Em.Route.extend({ route: "/", redirectsTo: 'home' }), home: Em.Route.extend({ route: '/home', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet({name: 'home'}); } }), // STATES profile: Em.Route.extend({ route: '/profile', connectOutlets: function(router, context) { var appController = router.get('applicationController'); appController.connectOutlet('profile'); } }), doOne: function() { alert("eins"); } }) });

解决方案

U can make a redirect from the index to the home route. Working example: jsfiddle/FRfBt/

更多推荐

Ember.js路由:如何设置默认路由立即呈现?

本文发布于:2023-08-02 17:03:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   如何设置   Ember   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!