so I created a survey link, and after completing a part of a survey, it will redirect to another page.
<Route path="part1survey/:id">
<Route index element={<Survey />} />
</Route>
<Route path="part2survey/:id">
<Route index element={<Survey2 />} />
</Route>
In this section, I have two path
. So after the user completed the first survey, it will get redirect to Survey2.
const handleSubmit = async (e) => {
e.preventDefault();
console.log(answer);
try {
if (id <= questions.length) {
await publicRequest.post(`/results`, answer);
const newId = parseInt(id) + 1;
if (newId === questions.length + 1) {
navigate(`/part2survey/1`);
} else {
navigate(`/part1survey/${newId}`);
}
}
else{
console.log("ERROR!")
}
setAnswer({
user_number: user_number,
user_category: user_category,
choice: [],
others: "",
});
setIsChange(false);
console.log(answer);
} catch (error) {
console.log(answer);
console.log(error);
}
};
But the problem is, after redirecting to the next path
and pick a choice, I suddenly get an error.
But previously, on the part1, I can answer a survey...
Index.js
const express = require('express');
const cors = require('cors');
const result = require('./routes/results/results.js')
const app = express()
app.use(cors());
app.use(express.json());
app.get('/', (req,res) =>{
res.send("Hello World")
})
//Users
app.use('/api/results', result)
app.listen(4000, () =>{
console.log(`Website is running at port http://localhost:${4000}`)
})