2014-02-04 01:20:55 +08:00
|
|
|
var render = require("./render");
|
|
|
|
|
|
|
|
// Event when another page should be opened
|
|
|
|
// Maybe hook click on links, hashchange or popstate
|
|
|
|
window.onLinkToPage = function onLinkToPage(name) { // name is "a" or "b"
|
|
|
|
// require the page with a dynamic require
|
|
|
|
|
|
|
|
// It's important that this require only matches the pages
|
|
|
|
// elsewise there is blood in the bundle. Here this is done with a
|
|
|
|
// specific file prefix. It's also possible to use a directory,
|
|
|
|
// overwriting the RegExp with the ContextReplacementPlugin, or
|
|
|
|
// using the require.context method.
|
|
|
|
|
|
|
|
// The bundle-loader is used to create a chunk from the page
|
|
|
|
// -> Pages are only loaded on demand
|
|
|
|
|
|
|
|
// This line may throw a exception on runtime if the page wasn't found.
|
2016-10-26 05:03:59 +08:00
|
|
|
var pageBundle = require("bundle-loader!./" + name + "Page");
|
2014-02-04 01:20:55 +08:00
|
|
|
|
|
|
|
// Wait until the chunk is loaded
|
|
|
|
pageBundle(function(page) {
|
|
|
|
render(page);
|
|
|
|
});
|
2016-10-26 05:03:59 +08:00
|
|
|
}
|