@blumjs/router
Advanced tools
Comparing version 7.2.0 to 7.2.1
{ | ||
"name": "@blumjs/router", | ||
"version": "7.2.0", | ||
"version": "7.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "exports": { |
@@ -5,3 +5,3 @@ <div align="center"> | ||
# Not stable! | ||
# Not tested! Will arround March 15. | ||
@@ -36,3 +36,9 @@ # Description | ||
``` | ||
import { useInitRouter, createDisableBackBrowserRouteMiddleware, createRouteMiddleware, historyPush } from '@blumjs/router'; | ||
import { | ||
useInitRouter, | ||
createCatchBackBrowserRouteMiddleware, | ||
createDisableBackBrowserRouteMiddleware, | ||
createRouteMiddleware, | ||
blumRouter | ||
} from '@blumjs/router'; | ||
@@ -46,4 +52,7 @@ const App = () => { | ||
}, | ||
//first arg is the name of route; second callback, that fired when pushed back in browser | ||
//first arg is the name of route; second callback, that fired when pushed back in browser | ||
createCatchBackBrowserRouteMiddleware('Alert', (storeRoutes, prevRoutes) => back()); | ||
//the same as createCatchBackBrowserRouteMiddleware, but make auto historyPush storeRoutes | ||
createDisableBackBrowserRouteMiddleware('Loading', (storeRoutes, prevRoutes) => console.log('loading, please wait...')), | ||
//custom middleware | ||
createRouteMiddleware((storeRoutes, prevRoutes) => { | ||
@@ -54,3 +63,3 @@ if(navigator.onLine){ | ||
} | ||
historyPush({view: 'ConnectionError', panel: 'Offline', modal: null, popout: null}); | ||
blumRouter.historyPush({view: 'ConnectionError', panel: 'Offline', modal: null, popout: null}); | ||
return false; | ||
@@ -83,10 +92,5 @@ }) | ||
``` | ||
import { setRoutes, setActiveView, setActivePanel, setActiveModal, setActivePopout } from '@blumjs/router'; | ||
import { setActiveViewPanel, setActivePanel, setActiveModal, setActivePopout } from '@blumjs/router'; | ||
//setRoutes accept partial routes | ||
setRoutes({view: 'Main', panel: 'Home'}); | ||
setRoutes({modal: 'Onboarding'}); | ||
setRoutes({panel: 'Game', popout: 'Loading'}); | ||
setActiveView('Main'); | ||
setActiveViewPanel({view: 'Main', panel: 'Home'}); | ||
setActivePanel('Home'); | ||
@@ -102,3 +106,21 @@ setActiveModal('Notifications'); | ||
//if you want to, that state changed only before middlewares: | ||
back({ | ||
isDispatchChangeStateEventBeforeMiddleware: true, | ||
isDispatchChangeStateEventAfterMiddleware: false | ||
}); | ||
//back is async function and you can't await it. So use options beforeBackHandledCallback (triggered after window.history.back and before middlewares) and afterBackHandledCallback (triggered when passed all midlewares) | ||
back({ | ||
beforeBackHandledCallback: () => { | ||
console.log("I triggered before middlewares") | ||
}, | ||
afterBackHandledCallback: () => { | ||
console.log("I triggered after middlewares") | ||
} | ||
}); | ||
//default: isDispatchChangeStateEventBeforeMiddleware = false, isDispatchChangeStateEventAfterMiddleware = true, and callbacks are null | ||
back(); | ||
``` | ||
@@ -105,0 +127,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63094
130