Skip to content

Instantly share code, notes, and snippets.

@somebody32
Last active February 5, 2016 17:38
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/c84285dcef72574a5fa0 to your computer and use it in GitHub Desktop.
Save somebody32/c84285dcef72574a5fa0 to your computer and use it in GitHub Desktop.
trying to load app in router's 404 handler
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 part of the main app, no async bundle loading here");
},
- handle404() {
- alert('404');
- },
+ handle404(path) {
+ const mini_app_name = AppFinder(path);
+
+ if (mini_app_name) {
+ require.ensure([], require => {
+ const App = require('./apps/' + mini_app_name + '/index.js').default;
+ App();
+ Backbone.history.loadUrl(); // just refreshing the current path, because we've added new paths that we can handle
+ });
+ } else {
+ alert('404');
+ }
+ },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment