2

ルーターは 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>

使用事例:

ユーザーが index.html#/xxxx という URL を入力したときに、要求された「ページ」が存在しないことを示す一種のエラー ページに遷移したいと考えています。

これまでのところ、解決策は見つかりませんでした...

4

2 に答える 2

8

次のようにキャッチオールルートを追加できます。

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");
    }
});
于 2013-08-06T15:15:33.723 に答える
3

Ember.JS: 無効な URL の処理方法は、別のアプローチを探している場合の良い例です。

于 2013-08-06T17:36:04.420 に答える