Post any code you think might be relevant (one fenced block per file)
//show in api/characters.js
// READ -> Show
export const getOneCharacter = (id) => {
return axios(`${apiUrl}/characters/${id}`)
}
//backend show route
// SHOW
// GET /characters/:id
router.get('/characters/:id', (req, res, next) => {
// req.params.id will be set based on the `:id` in the route
Character.findById(req.params.id)
.populate('owner') // Populate owner field if needed
.then(handle404)
.then((character) => res.status(200).json({ character: character.toObject() }))
// If an error occurs, pass it to the error handler
.catch(next);
});
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
What is your best guess as to the source of the problem?
the url is showing /characters/0 when "0" should be an object ID, maybe the front end is not properly passing a character id to the backend?
What things have you already tried to solve the problem?
I have tried console.logs in various places to see where its losing the correct id but I havent been able to find it
The useParams is grabbing whatever id is currently in your browsers URL, make sure on the index page when you have the Link to your show page, you're passing in the id and not the index
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
mern
What's the problem you're trying to solve?
show is not fetching objectid from database
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
What is your best guess as to the source of the problem?
the url is showing /characters/0 when "0" should be an object ID, maybe the front end is not properly passing a character id to the backend?
What things have you already tried to solve the problem?
I have tried console.logs in various places to see where its losing the correct id but I havent been able to find it
Paste a link to your repository here https://github.com/noahD0zer/BG3-Creator-Backend https://github.com/noahD0zer/BG3-Creator-Frontend