Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhanceApp() ctx.router is not a router instance #4204

Open
4 tasks done
davestewart opened this issue Sep 16, 2024 · 2 comments
Open
4 tasks done

enhanceApp() ctx.router is not a router instance #4204

davestewart opened this issue Sep 16, 2024 · 2 comments
Labels
docs Improvements or additions to documentation

Comments

@davestewart
Copy link

davestewart commented Sep 16, 2024

Describe the bug

The theme docs and code completion state that the router instance is exposed in enhanceApp() but it appears the router instance is actually a route instance, and doesn't conform to the Router interface.

CleanShot 2024-09-16 at 13 06 24

Reproduction

Initialize a new project, then add the following code to enhanceApp():

    console.log({ router })
    router.onAfterRouteChanged((to: string) => {
      console.log(`changed to: ${to}`)
    })

Expected behavior

We should be able to interact with the router instance

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 213.02 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.7.0 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  Browsers:
    Brave Browser: 122.1.63.169
    Chrome: 128.0.6613.138
    Chrome Canary: 130.0.6720.0
    Edge: 128.0.2739.79
    Safari: 17.5
  npmPackages:
    vitepress: ^1.3.4 => 1.3.4

Additional context

No response

Validations

@davestewart davestewart added the bug: pending triage Maybe a bug, waiting for confirmation label Sep 16, 2024
@brc-dd
Copy link
Member

brc-dd commented Sep 16, 2024

Ah, it's router, but that function is not exactly a hook. You need to define it - #2564 (comment)

router.onBeforeRouteChange = (to) => {
  console.log('onBeforeRouteChange', to)
}

@brc-dd brc-dd added docs Improvements or additions to documentation and removed bug: pending triage Maybe a bug, waiting for confirmation labels Sep 16, 2024
@davestewart
Copy link
Author

Aha! Yes, I think defo a docs issue.

Thanks for coming back so very quickly!!! 🥰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants