0

Im creating my first CRUD in Vue/Laravel and now I'm trying to send a create to my backend application, this is my code:

Frontend:

async addDespesa() {
  let uri = "api/despesas/create";
  const response = await axios.get(uri, this.despesa).then((response) => {
    this.$router.push({ name: "despesas" });
  });
},

Backend:

public function create()
{
    //
}

Errors in inspect on Browser:

>[vue-router] Route with name 'despesas' does not exist 

>Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/".
    at createRouterError 
at createNavigationDuplicatedError
at HashHistory.confirmTransition
at HashHistory.transitionTo
at eval
at HashHistory.push
at new Promise
 at VueRouter.push
at eval
4
  • Please post your back-end code as well :) Commented Nov 29, 2020 at 2:08
  • 1
    what methods are allowed for the api/despesas/create endpoint? is POST one of them Commented Nov 29, 2020 at 2:09
  • The endpoint was wrong. I changed post for get and another error appears. I edit the post with all my frontend, backend and error code Commented Nov 29, 2020 at 2:36
  • The error means you haven't defined a route named 'despesas'. Check the route definition has the name property. Commented Nov 29, 2020 at 5:48

1 Answer 1

1

Your backend seems fine, the problem is in the .then part of your Axios call:

this.$router.push({ name: "despesas" });

You should check your frontend routes (probably in a file called routes.js) and make sure you have a route named despesas. So something like this:

let routes = [
    {
        'path': '/path/to/despesas',
        'name': 'despesas',
        component: require('./path/to/despesas-component').default
    },
    
    ...

    other routes
];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.