I have several components displayed with react router that have dynamic url paths. An example path I have is
<Route path="/newproject/:id" onEnter={checkSesh} component= {ProjectDetails} />
When entering this component, I have a componentWillMount
function that extract the id
part of the url so that I can get the info for the correct project and render it on the ProjectDetails
component.
componentWillMount() {
var id = this.props.router.params.id
this.props.teamDetails(id);
}
this.props.teamDetails(id)
this calls a redux action creator that will make an axios request to an express route that will get the project info from the database.
export function teamDetails(id) {
return function(dispatch) {
axios.get('/getteaminfo/' + id)
.then(res => {
dispatch({ type: "SET_TEAM_DETAILS", payload: {
teamInfo: res.data.teamInfo,
admin: res.data.admin,
adminID: res.data.teamInfo.teamAdmin,
teamMembers: res.data.teamInfo.teamMembers
}
})
});
}
}
everything works fine upon visiting the page after already being logged in etc. But when I refresh the page /newproject/:id
, i get an error Uncaught SyntaxError: Unexpected token <
. An example url in my browser looks like http://localhost:3000/newproject/58df1ae6aabc4916206fdaae
. When I refresh this page, I get that error. The error is complaining about my <!DOCTYPE html>
tag at the very top of my index.html for some reason. This index.html is where all of React is being rendered.