最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Sails.js routes, with variables in url. ex games(ID HERE) - Stack Overflow

matteradmin2PV0评论

I have tried to find a guide how to get routes to work with variables in the url exemple : games/124512 and get that id to controllers in a variable.

My routes.js right now :

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

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

My GamesController.js right now :

var GamesController = {

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

I can write /games/sayHello or /games/sayWele but what I would like is to be able to write exemple /games/234234 or /games/234234/settings

Thanks! :)

I have tried to find a guide how to get routes to work with variables in the url exemple : games/124512 and get that id to controllers in a variable.

My routes.js right now :

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

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

My GamesController.js right now :

var GamesController = {

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

I can write /games/sayHello or /games/sayWele but what I would like is to be able to write exemple /games/234234 or /games/234234/settings

Thanks! :)

Share Improve this question asked Oct 7, 2014 at 13:33 jerrkanjerrkan 971 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You can set url slugs in your routes like the link shows, i.e. /games/:id. You can access them in your contoller via by name that you set in the route, i.e. req.param('id')

Post a comment

comment list (0)

  1. No comments so far