gpt4 book ai didi

ember.js - Ember : how to handle unexpected routes?

转载 作者:行者123 更新时间:2023-12-02 21:46:42 25 4
gpt4 key购买 nike

路由器会很好地处理 URL,并在路由存在时调用适当的路由。但是当路由不存在时如何处理呢?

app.js

App = Ember.Application.create();

App.Router.map(function () {
this.resource('about', { path: "/about" });
this.resource('admin', { path: "/admin" });
});

index.html

<script type="text/x-handlebars" id="about">
<h1>ABOUT</h1>
</script>

<script type="text/x-handlebars" id="admin">
<h1>ADMIN</h1>
</script>

用例:

当用户输入 URL index.html#/xxxx 时,我想转换到一种错误页面,指示所请求的“页面”不存在。

到目前为止,我还没有找到解决方案......

最佳答案

您可以像这样添加一条包罗万象的路线:

this.route('missing', { path: "/*path" });

然后在此路由内重定向。我的实现如下所示:

App.MissingRoute = Ember.Route.extend({
redirect : function(){
App.LOG.warn("No Route for given URL found. Will transition to Index Route instead.");
this.transitionTo("index");
}
});

关于ember.js - Ember : how to handle unexpected routes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18084086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com