0.0.3 • Published 3 years ago

next-pages-path-gen v0.0.3

Weekly downloads
295
License
MIT
Repository
github
Last release
3 years ago

next-pages-path-gen

Generate pages path for Next.js.

Install

$ yarn add -D next-pages-path-gen
$ npm i -D next-pages-path-gen

you can not use with npx

Setup

package.json

{
  "scripts": {
    "build:path": "next-pages-path-gen"
  }
}

Usage

import Link from "next/link"
import { pagesPath } from "../lib/path"

console.log(pagesPath.post.create.$query()) // { pathname: '/post/create' }
console.log(pagesPath.post._pid(1).$query()) // { pathname: '/post/[pid]', query: { pid: 1 }}

export default () => {
  const onclick = useCallback(() => {
    router.push(pagesPath.post._pid(1).$query())
  }, [])

  return (
    <>
      <Link href={pagesPath.post._pid(1).$query()} />
      <div onclick={onclick} />
    </>
  )
}

License

MIT License.