question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

can not use router.push() in composable and utils directory

See original GitHub issue

I tried to use useRouter() in composables directory and utils directory.

in composable directory

import { useRouter } from 'vue-router';

const router = useRouter()

export function navigateTo(url: string) {
  router.push(url)
}

in utils directory

import { useRouter } from 'vue-router';

const router = useRouter()

export function navigateTo(url: string) {
  router.push(url)
}

but it throws a undefined Error when I call navigateTo function in component 。

image

I create a mini repository here : https://github.com/weisiqian/nuxt3-app.git

_Originally posted by @weisiqian in https://github.com/nuxt/framework/discussions/1749#discussioncomment-1598478_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
weisiqiancommented, Nov 9, 2021

thank you @danielroe

0reactions
danielroecommented, Nov 8, 2021
import { useRouter } from 'vue-router';

export function useNavigation() {
  const router = useRouter()
  function navigateTo(url: string) {
    router.push(url)
  }
  return { navigateTo }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

react router history.push not loading expected component
After login successful I want redirect user to dashboard so for that: yield call(forwardTo, '/dashboard') which execute forwardTo function and ...
Read more >
How to change route in utils file #1749 - nuxt/framework - GitHub
I tried to use useRouter() in composables directory and utils directory. in composable directory. import { useRouter } from 'vue-router'; ...
Read more >
useRouter · Nuxt Composables
TIP: router.addRoute() adds route details into an array of routes and it is useful while building Nuxt plugins while router.push() on the other...
Read more >
next-type-safe-routes - npm
next-type-safe-routes parses the /pages folder in your Next.js app and generates types for all the pages and API routes in the application.
Read more >
Compose UI - Android Developers
In UI tests using a Compose rule, continuations resumed during withFrameNanos callbacks will not be dispatched until after all frame callbacks have finished ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found