Stephen Bunty Gomes's avatar

How to redirect from vue component to laravel blade file.

Hello everyone. I am working on a vue.js laravel project. I have used vue-router. I have used a jquery plugin that is not working in vue component. So, I have used the plugin in the blade.php file. Now, I want to redirect from vue component to laravel blade file in order to use that particular plugin which is important for my project. How can I achieve that? What are the ways of achieving the goal?

0 likes
4 replies
shaungbhone's avatar
https://stackoverflow.com/questions/53362724/laravel-vue-page-redirection
1 like
Stephen Bunty Gomes's avatar

Thank you for the response. I have found a solution. I used window.location.href = "location" to redirect to the api route from vue component and then loaded the laravel blade file. my code is given below

vue component.

<template>
   <div>
        <p>mybook</p>
        <button @click = "myBook">My Book</button>

        
   </div>
</template>
<script>
    export default {
        data:() => {
            return {

            }
        },

        mounted(){

        },

        methods: {
            myBook(){
                window.location.href = "api/mybook/pages";
                // this.$router.push('api/mybook/pages');
                // this.$store.dispatch('fetchmybook');
            }
        },
    }
    

</script>

api.php

	Route::get('mybook/pages', 'MyBookController@index');

controller

	public function index()
    {
        return view('books/mybook');
    }

But I am facing another problem now. Api route is not working if I put it inside middleware Auth:api even when I am logged in. It sends me back to the home component. It works only when I put it outside the middleware.

	Route::middleware('auth:api')->group(function() {
	
	}
	Route::get('mybook/pages', 'MyBookController@index');

Can you give me a suggestion about how can I get the route work while putting it inside route middleware auth:api?

1 like

Please or to participate in this conversation.