Sails.js, with variables in url. ex / games / (ID HERE)

I tried to find a guide on how to get routes for working with variables in a URL For example: games / 124512 and get this identifier for controllers in a variable.

My .js routes now:

'/': { view: 'homepage' }, '/games/': { controllers: 'games', } 

My GamesController.js right now:

 var GamesController = { sayHello: function (req, res) { res.view('homepage', { user : "sayHello", }); }, sayWelcome: function (req, res) { res.view('homepage', { user : "sayWelcome", }); } }; module.exports = GamesController; 

I can write / games / sayHello or / games / sayWelcome, but I would like to be able to write examples / games / 234234 or / games / 234234 / settings

Thanks!:)

+6
source share
1 answer

You can set url slugs in your routes as shown in the link, i.e. /games/:id . You can access them in your controller by the name that you specified on the route, i.e. req.param('id')

+4
source

Source: https://habr.com/ru/post/976366/


All Articles