routing¶
Source | routing |
---|
The routing library is a small routing library that handles top level DApp navigation. To be small as possible, it uses the navigo routing as helper library.
- On first loading, it checks a logged in user and in case of an unregistered user, it redirectes the browser to the onboarding DApp.
- It watches dynamically on route changes to trigger a new dapp.startDApp call when the root dapp hash changed.
- Sub DApp routing must be handled by DApps it self.
getActiveRootENS¶
routing.getActiveRootENS();
Gets the active root ens.
Returns¶
string
: The active root ens.
Example¶
// http://localhost:3000/index.html#/dashboard.evan/favorites.evan
routing.getActiveRootENS()
// result: dashboard.evan
getDefaultDAppENS¶
routing.getDefaultDAppENS();
Gets the default root DApp ens (mapped to the *.evan.network prefix). Default is dasboard.evan.
Returns¶
Promise
returns string
: default DApp ens path
Example¶
routing.getDefaultDAppENS()
http://localhost:3000/index.html => dashboard.evan http://taskboard.evan.network/index.html => taskboard.evan http://customer.evan.network/index.html => customer.evan
beforeRoute¶
routing.beforeRoute();
Prerouting checks to handle if the user was logged in and onboared. Navigates to onboarding / default dapp ens when necessary.
onRouteChange¶
routing.onRouteChange();
Function to check if the route DApp hash changed => run beforeRoute and set the route active. Start DApp when root DApp changed
initialize¶
routing.initialize();
Initialize the whole routing mechanism. Starts navigo, and runs initial route change for default route detection and dapp loading.
getRouteFromUrl¶
routing.getRouteFromUrl();
Takes the current url, removes #, /#, #/ and returns the original hash value without query params.
history¶
routing.history.push('dashboard.evan/favorites.evan');
The current navigation stack and includes every route that is opened from apps to handle a specific and logical go back function. Each application should implement an navigate function that pushes into this history array.
Important: Need to be filled by the application it self!!!
updateHistory¶
routing.updateHistory();
Takes the current navigation history and writes it to the sessionStorage if the user navigates to another page and navigates back