opral / inlang-paraglide-js

Tree-shakable i18n library build on the inlang ecosystem.
https://inlang.com/m/gerre34r/library-inlang-paraglideJs
22 stars 0 forks source link

useRouter does not allow routing to external links #119

Closed themataleao closed 1 month ago

themataleao commented 1 month ago

When I am using the useRouter component and route to an external link it throws me a type error:

Argument of type '"https://google.com"' is not assignable to parameter of type '/${string}'

'use client'
import { useRouter } from '@/lib/i18n'

export default function Button(props: {
}) {
  const router = useRouter()
  const { user } = useUser()

  const onClick = async () => {
    router.push("https://google.com")
  }

Any other suggestion to route to external URLS?

themataleao commented 1 month ago

I am able to trick the typescript compiler with

router.push(link as `/{string}`)

but I assume thats not intended :)

LorisSigrist commented 1 month ago

Good catch, that is indeed not intended 🙂 I'll fix that.

The workaround you used should work for the moment. Alternatively you could use the useRouter exported from next/navigation when you want external links. This won't translate internal links though

themataleao commented 1 month ago

You are right I could use the regular one from next/navigation. Thanks :)