Reputation: 31
I'm using: [email protected]. I want to redirect the user to a different page but after the insert the client it's refreshed. This means that i'm filling up a form, I store the data, I do the navigation and then with the client refresh I'm back to the form page.
// Methods.js
import { Meteor } from "meteor/meteor";
import { Players } from "../imports/api/players";
Meteor.methods({
insertPlayer(player) {
Players.insert(player);
}
})
I'm calling the method like this:
// New-player.jsx
Meteor.call("insertPlayer", player, (error) => {
if(error) {
alert("Oups something went wrong: " + error.reason);
} else {
this.props.history.push("/");
}
})
And i'm storing the values as:
// Players.js
Players.allow({
insert() { return false; },
update() { return false; },
remove() { return false; }
});
Players.deny({
insert() { return true; },
update() { return true; },
remove() { return true; }
})
Any idea what it might cause this behavior? I'm I missing any config?
The project can be found here: https://github.com/roedit/soccer-app
Upvotes: 0
Views: 65
Reputation: 268
I assume you are using a form submit event? Make sure before you call the Meteor Method insertPlayer
you are using event.preventDefault()
. If you do not event.preventDefault(), the page will refresh.
Upvotes: 1