Nested route parameters


#1

please help me out that how we can pass multiple parameters in routes.


#2

What have you tried so far?


#3

This is an example about passing multiple parameters to a route and showing them after it

First we declare our Route in this way


Route.get('/about/:name/:age', 'DemoController.index')

CLARIFICATIONS

  • As you see we have two params: name and age
  • We send this info an index method inside our DemoController

After in our DemoController we make the following


'use strict'

class DemoController {
    async index({ params }){
        let { name, age } = params
        return `${name} ${age}`
    }
}

module.exports = DemoController


  • As you see we use the params object to get the values sended by the user
  • After with destructuring we parse the data and assing every value to an specific variable
  • After we show them with the return action

Finally this will be a result in our web browser

Our URL


http://localhost:3333/about/virk/20

The result will be

virk 20


#4

Thank you so much sir… this help me out


#5

please if the answer was helpful; please mark it as the correct one