Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (41 sloc) 1.25 KB
import { PluginFactory } from 'router5'
const noop = () => {}
const loggerPlugin: PluginFactory = () => {
let startGroup, endGroup
if (console.groupCollapsed) {
startGroup = label => console.groupCollapsed(label)
endGroup = () => console.groupEnd()
} else if (console.group) {
startGroup = label => console.group(label)
endGroup = () => console.groupEnd()
} else {
startGroup = noop
endGroup = noop
}
console.info('Router started')
return {
onStop() {
console.info('Router stopped')
},
onTransitionStart(toState, fromState) {
endGroup()
startGroup('Router transition')
console.log('Transition started from state')
console.log(fromState)
console.log('To state')
console.log(toState)
},
onTransitionCancel() {
console.warn('Transition cancelled')
},
onTransitionError(toState, fromState, err) {
console.warn('Transition error with code ' + err.code)
endGroup()
},
onTransitionSuccess() {
console.log('Transition success')
endGroup()
}
}
}
export default loggerPlugin
You can’t perform that action at this time.