Backbone 应用未初始化
Backbone app not initializing
我正在开发 Backbone 应用程序。我有以下应用程序文件:
// src/app.js
var AppRouter = require('./router');
var App = new AppRouter();
已 link 编辑到索引页(link 有效,我已验证):
<!DOCTYPE html>
<html>
<head>
<title>Feedback Dev Test</title>
</head>
<body>
<script type="text/javascript" src="assets/js/app.js"></script>
</body>
</html>
这是路由器本身:
var Backbone = require('backbone');
var $ = require('jquery/dist/jquery');
var IndexView = require('./views/index');
Backbone.$ = $;
var AppRouter = Backbone.Router.extend({
routes: {
'': 'routeIndex',
'hello': 'hello'
},
routeIndex: function() {
if (!this.indexView) {
console.log('routeIndex called');
this.indexView = new IndexView();
}
},
hello: function() {
alert('HELLO');
}
});
module.exports = AppRouter;
当我导航到页面索引时,没有发生 routeIndex 事件(没有任何内容记录到控制台)。此外,当我导航到 /hello
时,也不会弹出警报。我做错了什么?
During page load, after your application has finished creating all of its routers, be sure to call Backbone.history.start(), or Backbone.history.start({pushState: true}) to route the initial URL.
我正在开发 Backbone 应用程序。我有以下应用程序文件:
// src/app.js
var AppRouter = require('./router');
var App = new AppRouter();
已 link 编辑到索引页(link 有效,我已验证):
<!DOCTYPE html>
<html>
<head>
<title>Feedback Dev Test</title>
</head>
<body>
<script type="text/javascript" src="assets/js/app.js"></script>
</body>
</html>
这是路由器本身:
var Backbone = require('backbone');
var $ = require('jquery/dist/jquery');
var IndexView = require('./views/index');
Backbone.$ = $;
var AppRouter = Backbone.Router.extend({
routes: {
'': 'routeIndex',
'hello': 'hello'
},
routeIndex: function() {
if (!this.indexView) {
console.log('routeIndex called');
this.indexView = new IndexView();
}
},
hello: function() {
alert('HELLO');
}
});
module.exports = AppRouter;
当我导航到页面索引时,没有发生 routeIndex 事件(没有任何内容记录到控制台)。此外,当我导航到 /hello
时,也不会弹出警报。我做错了什么?
During page load, after your application has finished creating all of its routers, be sure to call Backbone.history.start(), or Backbone.history.start({pushState: true}) to route the initial URL.