Reputation: 59
I have a public link on my react-router V5.
<Router history={browserHistory}>
<Switch>
<Route exact path="/colaborativo/:id" component={Colaborativo}/>
<PrivateRoute>
...
When I access the link through a button, the application works correctly: Retrieves the parameter from the url, subscribes to the collection and retrieves the document. As this is a public link, I need it to be accessible directly from the link, without going through a previous screen or pressing a button. But when I reload the page with the F5 key, or when I try to access from another tab through the link, the application does not work, as the Meteor synchronization does not happen and the props remain undefined. I get the error:
Uncaught TypeError: Cannot read properties of undefined
this is the portion of the code that makes the pub/sub:
export default withTracker(
() => {
let { id } = useParams();
console.log(id)
const handles = [
Meteor.subscribe(
"experienciaOne",
id
)
];
const loading = handles.some(handle => !handle.ready());
var laExp = Experiencias.findOne(id)
console.log(laExp)
return {
isLoading: loading,
Experiencia: laExp
};
}
)(Colaborativo);
This is the publication in my publish.js:
Meteor.publish("experienciaOne", function(id) {
let rta = Experiencias.find({ _id: id });
return rta
});
Upvotes: 0
Views: 51
Reputation: 59
I solved it by replacing the state by using the properties. Evidently, the state is executed before the sync.
Upvotes: 0