Skip to content

Instantly share code, notes, and snippets.

@somebody32
Last active July 16, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somebody32/969827a08d889817495efb7ae47c453c to your computer and use it in GitHub Desktop.
Save somebody32/969827a08d889817495efb7ae47c453c to your computer and use it in GitHub Desktop.
Webpack 2 Router diff
import Backbone from 'backbone';
import $ from 'jquery';
import AppFinder from './app_finder';
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 a part of the main app, it is lightweight and very actively used");
},
handle404(path) {
- const mini_app_name = AppFinder(path);
+ const mini_app = AppFinder(path);
- if (mini_app_name) {
+ if (mini_app) {
- const handler = System.import(`./apps/${mini_app_name}/index.js`);
+ const handler = System.import(`./apps/${mini_app.name}/index.js`);
handler.then(bundle => {
const App = bundle.default;
App();
Backbone.history.loadUrl(); // just refreshing the current path, because we've added new paths that we can handle
}).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