我正在尝试创建一个简单的多人游戏。我想在路由中使用随机生成的房间id,以便路由到新创建的大厅,但不能将功能返回给路由器。作为查询推送;我不知道为什么?你能帮我吗?
const RandomRoom = () =>{
let romstr = "";
for(let i=0; i<5; i++){
const randomElement = randomchars[Math.floor(Math.random() * randomchars.length)];
romstr += randomElement;
}
return romstr;
}
const handleSubmit = function () {
return function () {
if (!executed) {
const param = RandomRoom;
executed = true;
socket.emit("joinroom", data1);
console.log("roomid" + param);
router.push({
pathname: `/lobby/[lobbyid]`,
query: {param}
});
}
}
}()
你的路由器有问题。方法时,未向查询对象提供说客属性。
const param = RandomRoom;
router.push({
pathname: '/lobby/[lobbyid]',
query: { lobbyid: param },
});