QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.45k stars 1.26k forks source link

[✨] qwik-city: useLocation should provide makePath #4836

Open wmertens opened 11 months ago

wmertens commented 11 months ago

Is your feature request related to a problem?

When trying to redirect within the application, it's hard to do it properly.

Describe the solution you'd like

useLocation should return makePath function that takes path and/or params and/or query, merging those to return the correct absolute path for the application.

const {makePath, params} = useLocation()
return <div>
  <Link href={makePath({path:".."})}>Up</Link>
  <Link href={makePath({params: {id: Number(params.id)-1}})}>Previous</Link>
</div>

Describe alternatives you've considered

Adhoc path generation. People will often forget query strings and the base path

Additional context

No response

manucorporat commented 11 months ago

I don't think this belong in useLocation()

wmertens commented 11 months ago

@manucorporat is it because it would create overhead? How about a useMakePath() hook that calls useLocation?