SHARE
TWEET

Untitled

a guest Jun 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async changeRoute(newRoute) {
  2.  
  3.         const treeBuilder = module.Router.router.routingSnapshotTreeBuilder
  4.         const router = module.Router.router
  5.         const newRouteData = treeBuilder.buildRouteTree(newRoute)
  6.  
  7.         if (!newRouteData) {
  8.             throw Error(`Could not build tree for ${newRoute}`)
  9.         }
  10.  
  11.         const canGoOn = await router.canGoOn(window.location.pathname, newRouteData.guard)
  12.  
  13.         if (!canGoOn) {
  14.             history.back()
  15.             return
  16.         }
  17.  
  18.         router.currentSnapshot = newRouteData
  19.  
  20.         this.clearChildren()
  21.  
  22.         // To avoid error, set the attributes member to be empty object, if null or undefined
  23.         if (!newRouteData.attributes) {
  24.             newRouteData.attributes = {}
  25.         }
  26.         const newElement = document.createElement(newRouteData.element, newRouteData.attributes)
  27.         Object.keys(newRouteData.attributes).forEach(key => {
  28.             newElement.setAttribute(key, newRouteData.attributes[key])
  29.         })
  30.         this.appendChild(newElement)
  31.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top