LoginSignup
12
12

More than 5 years have passed since last update.

Backbone.Routerが動かないよー (つд⊂) ってときの確認事項

Last updated at Posted at 2014-04-30

newしてない

  var MyRouter = Backbone.Router.extend({
  });
+ router = new MyRouter();

してください。

history.start()してない

  var router = new MyRouter();
+ Backbone.history.start();

してください。

pushStateの指定がない

- Backbone.history.start();
+ Backbone.history.start({ pushState:true });

この指定をしないと、ハッシュ"#"を使ったURLとして解釈されます。普通の静的っぽいURLで動かすならこの指定が必要。

routing冒頭の"/"を取り除いていない

  routes: {
-   '/': 'home',
-   '/users/:id': 'showUser'
+   '': 'home',
+   'users/:id': 'showUser'
  },

"/"あると駄目。なんでだろね。

404用のroutingで上書きされてる

routes'*path':'notFound'設定したりするんだけど、登録順序を考慮してやらんと全部notFoundになっちゃう。全部routesに書くんじゃなくて、notFoundだけ書いておいて、他は初期処理でrouteを使って登録すると良い。

(気が向いたらもっと詳しく書く)

その他

コメントで教えてください。追加します。

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12