本文介绍了Ember路由器不会在Chrome和Safari中更新网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了在ember.js中的跟踪。代码工作到某一点。



当我以root url ie'/'输入应用程序时,该URL不会更改,在该位置应该转到tasks.index并通过显示# /任务。



但是当我转到'#/ tasks'时,它的行为正确,并从索引视图中显示hello。



我正在使用Google Chrome版本19和ember.js边缘。



任何帮助都非常感谢。

  App = Em.Application.create({}); 

App.IndexView = Em.View.extend({
template:Em.Handlebars.compile(
'hello world from index'

});

App.ShowView = Em.View.extend({
template:Em.Handlebars.compile(
'hello world from show'

});

App.Router = Ember.Router.extend({
location:'hash',
rootElement:#my-app,
enableLogging:true,

root:Ember.State.extend({
index:Ember.State.extend({
route:'/',
redirectsTo:'tasks.index '
}),

任务:Ember.State.extend({
route:'/ tasks',

index:Ember.ViewState。扩展({
route:'/',
view:App.IndexView
}),

显示:Ember.ViewState.extend({
路线:'/ show',
视图:App.ShowView
})
})
})
});

App.initialize();


解决方案

看到这个jsFiddle:



代码 - >



所有你需要做的是改变 redirectsTo:'tasks.index' code>到 redirectsTo:'tasks'



当目的地状态起始时,您不需要使用 redirectsTo 指定目的地状态的起始路径路线定义(如您所做)。


I have implemented to following in ember.js. The code works up to a certain point.

The URL does not change when I enter the application at root url i.e. '/' where it should go to tasks.index and reflect the changes in the url by showing #/tasks.

But it behaves correctly when I go to '#/tasks' and shows the message 'hello from index view'.

I am using Google Chrome version 19 and ember.js edge.

Any help is very much appreciated.

App = Em.Application.create({});

App.IndexView = Em.View.extend({
    template: Em.Handlebars.compile(
        'hello world from index'
    )
});

App.ShowView = Em.View.extend({
    template: Em.Handlebars.compile(
        'hello world from show'
    )
});

App.Router = Ember.Router.extend({
    location: 'hash',
    rootElement: "#my-app",
    enableLogging: true,

    root: Ember.State.extend({
        index: Ember.State.extend({
            route: '/',
            redirectsTo: 'tasks.index'
        }),

        tasks: Ember.State.extend({
            route: '/tasks',

            index: Ember.ViewState.extend({
                route: '/',
                view: App.IndexView
            }),

            show: Ember.ViewState.extend({
                route: '/show',
                view: App.ShowView
            })
        })
    })
});

App.initialize();
解决方案

See this jsFiddle:

Code->http://jsfiddle.net/ud3323/WLcRQ/

Debug-> http://jsfiddle.net/ud3323/WLcRQ/show/

All you needed to do was change redirectsTo: 'tasks.index' to redirectsTo: 'tasks'.

You don't need to specify the destination state's starting route when using redirectsTo when the destination state has a starting route defined (as you've done).

这篇关于Ember路由器不会在Chrome和Safari中更新网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:20