-
-
Save mfrancois3k/bab89337552790e84c1b15d1e952b7c6 to your computer and use it in GitHub Desktop.
Barba v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Internally, do something like this | |
| Promise | |
| .all([ | |
| this.loadNewContent, | |
| this.transitionOut({ | |
| fromRoute, | |
| event, | |
| oldContainer, | |
| promise | |
| }) | |
| ]) | |
| .then(this.transitionIn({ | |
| fromRoute, | |
| event, | |
| oldContainer, | |
| newContainer, | |
| promise | |
| })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Barba from 'barba.js' | |
| // Github says "Contents files can't be in subdirectories or include '/' in the name" but these should be in a subdir | |
| import home from 'routes.home.js' | |
| import post from 'routes.post.js' | |
| import posts from 'routes.posts.js' | |
| Barba.init({ | |
| routes: [home, post, posts], // Order would be important, when looking for `path` property | |
| opts: {}, | |
| defaults: { | |
| onEnter() {}, | |
| onLeave() {}, | |
| transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {}, | |
| transitionOut({toRoute, event, oldContainer, promise}) {} // Out transition can't have `newContainer` yet | |
| } | |
| }) | |
| // Barba.addRoute(...) | |
| // Barba.goTo(...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| name: 'home', | |
| path: '/', | |
| onEnter() { | |
| // init components for this page, like a slider, calendar, ... | |
| }, | |
| onLeave() { | |
| // destroy components to avoid memory leaks | |
| }, | |
| transitionIn({fromRoute, event, oldContainer, newContainer, promise}) { | |
| // do some animation | |
| promise.resolve() | |
| }, | |
| transitionOut({toRoute, event, oldContainer, promise}) { | |
| if( toRoute.name === 'blog' ) { | |
| // do animation | |
| promise.resolve() | |
| } else { | |
| // do another animation | |
| promise.resolve() | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| name: 'post', | |
| path: '/news/*', | |
| onEnter() {}, | |
| onLeave() {}, | |
| transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {}, | |
| transitionOut({toRoute, event, oldContainer, promise}) {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| name: 'posts', | |
| path: '/news', | |
| onEnter() {}, | |
| onLeave() {}, | |
| transitionIn({fromRoute, event, oldContainer, newContainer, promise}) {}, | |
| transitionOut({toRoute, event, oldContainer, promise}) {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment