(urlManager: UrlManager)
| 35 | |
| 36 | // initialize the router with current url in browser |
| 37 | async initialize(urlManager: UrlManager) { |
| 38 | this._manager = urlManager; |
| 39 | this._parser = await adapterManager.getCurrentAdapter().resolveRouterParser(); |
| 40 | const { path: pathname, query, fragment } = vscode.Uri.parse(await this._manager.href()); |
| 41 | const path = pathname + (query ? `?${query}` : '') + (fragment ? `#${fragment}` : ''); |
| 42 | |
| 43 | this._state = await this._parser.parsePath(path); |
| 44 | this._history = createMemoryHistory({ initialEntries: [path] }); |
| 45 | |
| 46 | this._history.listen(async ({ action, location }) => { |
| 47 | const prevState = this._state; |
| 48 | const targetPath = `${location.pathname}${location.search}${location.hash}`; |
| 49 | const routerParser = await adapterManager.getCurrentAdapter().resolveRouterParser(); |
| 50 | |
| 51 | this._manager?.[action === Action.Push ? 'push' : 'replace'](targetPath); |
| 52 | this._state = await routerParser.parsePath(targetPath); |
| 53 | super.notifyListeners(this._state, prevState); |
| 54 | }); |
| 55 | this._barrier.open(); |
| 56 | } |
| 57 | |
| 58 | // get the routerState for current url |
| 59 | public async getState(): Promise<RouterState> { |
no test coverage detected