| 365 | */ |
| 366 | @Method() |
| 367 | setRouteId( |
| 368 | id: string, |
| 369 | params: ComponentProps | undefined, |
| 370 | direction: RouterDirection, |
| 371 | animation?: AnimationBuilder |
| 372 | ): Promise<RouteWrite> { |
| 373 | const active = this.getActiveSync(); |
| 374 | if (matches(active, id, params)) { |
| 375 | return Promise.resolve({ |
| 376 | changed: false, |
| 377 | element: active.element, |
| 378 | }); |
| 379 | } |
| 380 | |
| 381 | let resolve: (result: RouteWrite) => void; |
| 382 | const promise = new Promise<RouteWrite>((r) => (resolve = r)); |
| 383 | let finish: Promise<boolean>; |
| 384 | const commonOpts: NavOptions = { |
| 385 | updateURL: false, |
| 386 | viewIsReady: (enteringEl) => { |
| 387 | let mark: () => void; |
| 388 | const p = new Promise<void>((r) => (mark = r)); |
| 389 | resolve({ |
| 390 | changed: true, |
| 391 | element: enteringEl, |
| 392 | markVisible: async () => { |
| 393 | mark(); |
| 394 | await finish; |
| 395 | }, |
| 396 | }); |
| 397 | return p; |
| 398 | }, |
| 399 | }; |
| 400 | |
| 401 | if (direction === 'root') { |
| 402 | finish = this.setRoot(id, params, commonOpts); |
| 403 | } else { |
| 404 | // Look for a view matching the target in the view stack. |
| 405 | const viewController = this.views.find((v) => matches(v, id, params)); |
| 406 | |
| 407 | if (viewController) { |
| 408 | finish = this.popTo(viewController, { |
| 409 | ...commonOpts, |
| 410 | direction: 'back', |
| 411 | animationBuilder: animation, |
| 412 | }); |
| 413 | } else if (direction === 'forward') { |
| 414 | finish = this.push(id, params, { |
| 415 | ...commonOpts, |
| 416 | animationBuilder: animation, |
| 417 | }); |
| 418 | } else if (direction === 'back') { |
| 419 | finish = this.setRoot(id, params, { |
| 420 | ...commonOpts, |
| 421 | direction: 'back', |
| 422 | animated: true, |
| 423 | animationBuilder: animation, |
| 424 | }); |