admin管理员组文章数量:1024675
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 badges1 Answer
Reset to default 5You 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')
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 badges1 Answer
Reset to default 5You 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')
本文标签: javascriptSailsjs routeswith variables in url ex games(ID HERE)Stack Overflow
版权声明:本文标题:javascript - Sails.js routes, with variables in url. ex games(ID HERE) - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745617102a2159356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论