npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@onlywatch/nextjs-route-segments-params

v0.4.1

Published

Type-safe Dynamic Routes URL segments params and state manager for Next.js

Readme

📦 @onlywatch/nextjs-route-segments-params

Sponsor npm Coverage Dependencies Package Size

NextJS-App-Router NextJS-supports-version React-supports-version

[!NOTE]

🔋 improve developers' experience in handling [[...segmentsParams]] route params for Dynamic Routes Segments Params in Next.js

✨ Motivation

since...

i wanna to...

  • take /mall/query/rtx 5090 instead of /mall?query=rtx 5090

and...

  • manage the Segments Params and URL changes when updating the state in the Client Component

🖼️ Sequence Diagram

  • useSegments is used in Client Component
  • parseSegments is used in Server Component
sequenceDiagram
    participant User as 🙎‍♂️ User
    participant NextJS as Next.js
    participant RSC as Server Component
    participant RCC as Client Component
    participant Input as Input Element
    participant Submit as Submit Button

    User->>NextJS: visit URL '/mall/query/iphone'
    note over User,NextJS: route: /mall/[[...segmentsParams]]/page.tsx

    NextJS->>RSC: props.params.segmentsParams = ['query', 'iphone']
    RSC->>RSC: parseSegments(['query'], ['query', 'iphone'])
    note over RSC: returns { query: 'iphone' }

    RSC->>RCC: render with initial params
    RCC->>RCC: useSegments(['query'])
    note over RCC: const { params, setParams, pushUrl, replaceUrl }

    RCC->>Input: render controlled input
    note over Input: value={params.query} // 'iphone'

    User->>Input: 🙎‍♂️ typing 'rtx 5090'
    Input->>RCC: onChange event
    RCC->>RCC: setParams((prev) => ({...prev, query: 'rtx 5090'}))
    note over RCC: internal state updated
    RCC->>Input: re-render with new value
    note over Input: value={params.query} // 'rtx 5090'

    User->>Submit: 🙎‍♂️ click submit button
    Submit->>RCC: onClick event
    RCC->>RCC: pushUrl()
    RCC->>NextJS: router.push('/mall/query/rtx 5090')
    NextJS->>User: URL changed & page re-rendered
    note over User,NextJS: new URL: /mall/query/rtx 5090

✨ Basic Example

🧩 NextPage, the Server Component

import { parseSegments } from '@onlywatch/nextjs-route-segments-params/utils'

export async function generateStaticParams() {
  const routes: { params: string[] }[] = []

  // 💡 pre-rendered logic
  routes.push({ params: ['brand', 'nvidia', 'query', 'rtx 5090'] })

  return routes
}

export default async function NextPage(
  props: PageProps<'/[locale]/mall/[[...segmentsParams]]'>,
) {
  // 💡 segmentsParams returns `['brand', 'nvidia', 'query', 'rtx 5090']`
  const { segmentsParams = [] } = await props.params

  // 💡 params returns `{ brand: 'nvidia', query: 'rtx 5090' }`
  const params = parseSegments(['brand', 'query'], segmentsParams)

  return <div>...</div>
}

🧩 React, the Client Component

'use client'

import { useSegments } from '@onlywatch/nextjs-route-segments-params/hooks'

export function ReactClientComponent() {
  const { params, setParams, pushUrl, replaceUrl } = useSegments([
    'brand',
    'query',
  ])

  return (
    <div>
      <pre>{JSON.stringify(params, null, 2)}</pre>

      <input
        placeholder='Search...'
        value={params.query}
        onChange={(event) => {
          setParams((prev) => ({ ...prev, query: event.target.value }))
        }}
      />

      <button
        onClick={() => {
          setParams((prev) => ({ ...prev, brand: 'nvidia' }))
        }}
      >
        Nvidia
      </button>

      <button
        onClick={() => {
          setParams((prev) => ({ ...prev, query: 'rtx 5090' }))
        }}
      >
        query
      </button>

      <button
        onClick={() => {
          pushUrl()
        }}
      >
        Push a new URL to History stack
      </button>

      <button
        onClick={() => {
          replaceUrl()
        }}
      >
        Replace URL in History stack
      </button>
    </div>
  )
}