Last active
December 10, 2015 09:48
-
-
Save athap/4416584 to your computer and use it in GitHub Desktop.
Content of application.js for adding Require.js to Backbone.js application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------- | |
application.js | |
----------------------------------------------- | |
require [ | |
'backbone', | |
'path/to/router/with/index/handler'], | |
(Backbone, IndexRouter) -> | |
$ -> | |
Main = new IndexRouter() | |
Backbone.history.start() | |
----------------------------------------------- | |
requirejs.yml | |
----------------------------------------------- | |
modules: | |
- name: 'application' | |
shim: { | |
'backbone': { | |
# These script dependencies should be loaded before loading | |
# backbone.js | |
deps: ['underscore', 'jquery'], | |
# Once loaded, use the global 'Backbone' as the | |
# module value. | |
exports: 'Backbone' | |
} | |
} | |
------------------------------------------------ | |
MainRouter.js | |
------------------------------------------------ | |
define [ | |
'backbone'], | |
(Backbone, $) -> | |
class IndexRouter extends Backbone.Router | |
routes: | |
'': 'index' | |
index: () -> | |
alert("wooo..It works") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment