简体   繁体   中英

Meteor restarts client after Meteor.call()

I'm using: meteor-base@1.4.0. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM