https://github.com/goto-bus-stop/choo-lazy-route
lazy load choo routes from split bundles
https://github.com/goto-bus-stop/choo-lazy-route
Last synced: 2 months ago
JSON representation
lazy load choo routes from split bundles
- Host: GitHub
- URL: https://github.com/goto-bus-stop/choo-lazy-route
- Owner: goto-bus-stop
- License: other
- Created: 2018-02-12T13:41:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-23T13:28:12.000Z (over 7 years ago)
- Last Synced: 2025-04-16T00:07:07.121Z (2 months ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 16
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# choo-lazy-route
```js
var app = choo()
var splitRequire = require('split-require')
var lazyRoute = require('choo-lazy-route')()app.use(lazyRoute)
app.route('/lazy-route', lazyRoute(function (cb) {
splitRequire('./views/lazyView', cb)
}))
```## API
### `lazyRoute = require('choo-lazy-route')()`
Create an instance of the lazy route manager.
### `app.use(lazyRoute)`
Associate the lazy route manager with an app. The `lazyRoute` store also configures the app to take advantage of the experimental prefetch feature in bankai, so that server side rendering will include lazy routes.
### `app.route('/', lazyRoute(function load() {}))`
Create a lazy route. The `load` function can return a Promise or use the callback in its first parameter.
### Events
The lazy-route store emits the events listed below.
#### `lazy-route:load(route)`
Emitted when a route starts loading. `route` is a string.
#### `lazy-route:loaded(route, view)`
Emitted when a route has loaded successfully. `route` is a string. `view` is the view function that was loaded.
## todo
- timeout
- loading view (show after 700ms or so)