Last active
July 16, 2016 16:49
-
-
Save somebody32/becf78285dd47081c94b913ef05e60ec to your computer and use it in GitHub Desktop.
webpack 2 router example
This file contains 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
import Backbone from 'backbone'; | |
import $ from 'jquery'; | |
import AppFinder from './app_finder_test'; | |
export default Backbone.Router.extend({ | |
routes: { | |
'': 'home', | |
'main_app_part': 'mainAppPart', | |
'*handleMissingRoute': 'handle404' | |
}, | |
home() { | |
$('#app').html("You're on the home page"); | |
}, | |
mainAppPart() { | |
$('#app').html("You're viewing part of the main app, no async bundle loading here"); | |
}, | |
handle404(path) { | |
const mini_app_name = AppFinder(path); | |
if (mini_app_name) { | |
- const handler = require('bundle!./apps/' + mini_app_name + '/index.js'); | |
- handler(bundle => { | |
+ const handler = System.import(`./apps/${mini_app_name}/index.js`); | |
+ handler.then(bundle => { | |
const App = bundle.default; | |
App(); | |
Backbone.history.loadUrl(); | |
- }); | |
+ }).catch(() => alert("can't load the bundle")); | |
} else { | |
alert('404'); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment