Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic routing with multiple parameters in Next js - File Structure

I want to create dynamic pages in nextjs to match the following route users/[user]/[dashboard]. My file structure

pages/
 users/
  -[user].js       // will match for /users/123
  - index.js        // will match for /users
    dashboard/
      - [dashboard].js   // will match for /users/1234/ABCD

I'm only receiving the [user] in the query param and not the [dashboard] inside the [dashboard].js . Can someone explain how to arrange file structure to match users/[user]/[dashboard]

like image 317
Ibra Avatar asked Nov 26 '25 12:11

Ibra


1 Answers

To match the following dynamic routes users/[user]/[dashboard] you can structure your pages folder as follows:

pages/
  users/      
    index.js        // Matches `/users` route
    [user]/   
      index.js      // Matches `/users/user123` routes
      [dashboard]/
        index.js    // Matches `/users/user123/dashboardABC` routes
like image 72
juliomalves Avatar answered Dec 01 '25 01:12

juliomalves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!