Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async changeRoute(newRoute) {
- const treeBuilder = module.Router.router.routingSnapshotTreeBuilder
- const router = module.Router.router
- const newRouteData = treeBuilder.buildRouteTree(newRoute)
- if (!newRouteData) {
- throw Error(`Could not build tree for ${newRoute}`)
- }
- const canGoOn = await router.canGoOn(window.location.pathname, newRouteData.guard)
- if (!canGoOn) {
- history.back()
- return
- }
- router.currentSnapshot = newRouteData
- this.clearChildren()
- // To avoid error, set the attributes member to be empty object, if null or undefined
- if (!newRouteData.attributes) {
- newRouteData.attributes = {}
- }
- const newElement = document.createElement(newRouteData.element, newRouteData.attributes)
- Object.keys(newRouteData.attributes).forEach(key => {
- newElement.setAttribute(key, newRouteData.attributes[key])
- })
- this.appendChild(newElement)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement