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

Get url string of pagesPath #141

Open
IRediTOTO opened this issue Aug 31, 2022 · 3 comments
Open

Get url string of pagesPath #141

IRediTOTO opened this issue Aug 31, 2022 · 3 comments

Comments

@IRediTOTO
Copy link

IRediTOTO commented Aug 31, 2022

Description

Hi, I many times we need get final url of pagesPath
Example:

const urlObject= pagesPath.dashboard.project._projectId("abc").$url();
// return { pathname: '/dashboard/project/[projectId]' as const, query: { projectId }, hash: url?.hash }
// But many times we will need the final string, like use in window.open
window.open("Need an url string here, not object")

Describe the solution you'd like

This will be good, i think
pagesPath.dashboard.project._projectId("abc").$urlString;

Additional context

image

@matamatanot
Copy link

matamatanot commented Dec 19, 2022

Next.js new AppRouterInstance's push , replace and prefetch methods accept href:string. So, this feature is needed.

https://github.com/vercel/next.js/blob/b8ae447b0fdc12553b4eacd26595e4054ffcf415/packages/next/shared/lib/app-router-context.ts#L68-L95

@qwexvf
Copy link

qwexvf commented Mar 17, 2023

@solufa any updates on this?

@qwexvf
Copy link

qwexvf commented Mar 18, 2023

A bit old but a workaround is to use nextjs resolveHref function you will get the full href path string
https://github.com/vercel/next.js/blob/b8ae447b0fdc12553b4eacd26595e4054ffcf415/packages/next/shared/lib/router/router.ts#L223

import { resolveHref } from 'next/dist/shared/lib/router/router'
const paths = resolveHref(route, $pagesPath.post._pid(1).$url(), true)[1] // you need to pass router of useRouter

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

No branches or pull requests

3 participants