Comments (2)
It's not currently possible to extend route configuration itself dynamically. But in practise it might not be a problem. As long as you define the route map upfront, you can then still dynamically load parts of your app. We do this in production. For example:
// app.js
let cherrytree = require('cherrytree')
let resolvers = require('./routing/resolvers')
let loadCode = require('./routing/loadCode')
let router = cherrytree()
router.use(loadCode)
router.map(function (route) {
route('application', { resolver: resolvers.application }, function () {
route('logout')
route('list', { resolver: resolvers.list }, function () {
route('list.tab')
})
route('item', { resolver: resolvers.item }, function () {
route('item.details')
})
})
})
// routing/resolvers.js
let resolvers = {}
resolvers.application = function (name, cb) {
require.ensure([], function (require) {
cb(require('app/modules/application/routes')[name])
}, 'list-routes')
}
resolvers.list = function (name, cb) {
require.ensure([], function (require) {
cb(require('app/modules/list/routes')[name])
}, 'list-routes')
}
resolvers.item = function (name, cb) {
require.ensure([], function (require) {
cb(require('app/modules/item/routes')[name])
}, 'item-routes')
}
// app/modules/item/routes.js
module.exports = {
'item': require('./itemComponent'),
'item.details': require('./itemDetailsComponent')
}
// routing/loadCode.js
let when = require('when')
module.exports = function loadCode (transition) {
return when.map(transition.routes, function (memo, route) {
return resolve(route, transition.routes).then(function (Component) {
route.component = Component
})
})
}
function resolve (route, routes) {
let r = route
while (r) {
if (r.options.resolver) {
// this route has a resolver configured
return when.promise(resolve => r.options.resolver(name, resolve))
} else {
// walk up to the parent routes to find a resolver
r = routes[routes.indexOf(r) - 1]
}
}
throw new Error('Couldn\'t find a route resolver for ' + route.name)
}
And now webpack would build list page routes and item page routes into separate bundles and cherrytree would load those bundles dynamically as part of transitioning to those pages.
I'll have to take a closer look at react-router's API for this as they seem to have less boilerplate.
from cherrytree.
Many thanks for your work. I think this library has a right balance between functionality, flexibility and size.
Just wanted to know if the feature is already available but is not a deal breaker. Closing the issue
from cherrytree.
Related Issues (20)
- Fix tests. Oopsy. HOT 1
- Handle url Entries HOT 2
- Menu has dark blue highlights on black text HOT 1
- Menu has dark blue highlights on black text HOT 1
- Feature request: Ability to drag-and-drop images or to embed files HOT 2
- Are url hashes supported with pushState: true? HOT 9
- query param with urlencoded newline breakes route detection HOT 1
- Clarify Route Nesting example in the guide HOT 1
- Error transitioning to an abstract route with an index route HOT 3
- Transition silently
- Transition resolve handler added by middleware runs after handler added by application HOT 10
- Saucelabs build is failing HOT 2
- Route names must be unique error! But different leaf nodes. HOT 1
- Unable to generate url for abstract routes HOT 4
- The latest release in npm is not compiled to ES5 (?) HOT 1
- Consider replacing webpack by rollup
- cherrytree abandoned? HOT 3
- Interest in keeping cherrytree development HOT 7
- Provide typescript definitions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cherrytree.