我的应用程序当前有两个页面,Page1 和 Page2。在 Page1 上,我执行以下操作以使用 Expo Router 打开 Page2:
<Link href="/page2" asChild>
<TouchableOpacity>
<Text>Go to Page 2</Text>
</TouchableOpacity>
</Link>
在第 2 页上,我有一个包含两个字段和一个提交按钮的表单。当用户点击“提交”按钮时,它将数据发送到我的后端,后端返回一个对象。此时,我需要关闭 Page2 将该对象传递回 Page1,但我不确定如何使用 Expo Router 执行此操作。
第2页的提交功能:
const submit = async () => {
try {
const response = await postRequest('form/insert', { name: name, amount: amount });
const json = response.data;
console.log(response);
// How do I send the json data back to Page1?
} catch(error) {
console.log(error);
}
}
我该怎么做?
谢谢你
第 1 页:
const [value, updateValue] = useState(1)
navigate('page2', { updateValue : updateValue }
第2页:
pop()
updateValue(2)