3

I'm trying to make a link to a Laravel view called faq.blade.php from my Vue component, I tried to use axios and even when it returns the console.log I left after the response it isn't loading the view. How could I solve it?

FaqController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class FAQController extends Controller
{
    public function index(){
        return view('main.faq');
    }
}

I try to call it from this component: Main.vue (which is in the '/' route)

    <b-list-group-item align="left" @click="faq"><strong>></strong> FAQ</b-list-group-item>
    <b-list-group-item align="left" @click="services"><strong>></strong> Services</b-list-group-item>


<script>
export default {
    methods: {
        faq() {
        axios.get('/faq')

            .then(res => {
                console.log("faq");
            })
        },
        services(){
        axios.get('/services')

            .then(res => {
                console.log("services");
            })
        }
    }
}
</script>

Routes: web.php

Route::get('/', function () {
    return view('main.landing');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/faq', 'FAQController@index')->name('faq');
Route::get('/services', 'ServicesController@index')->name('services');
1
  • The response will return the block of HTML in the view as a response, if you want to load that view into the page, simply redirect Commented Nov 3, 2019 at 15:16

1 Answer 1

2

The Axios call will get the block of HTML as a string in the response, you don't want to do that, if you want to load that view into the browser, simply redirect to that route

export default {
    methods: {
        faq() {
            window.location = "/faq";
        },
        services() {
            window.location = "/services";
        }
    }
};

But if you want the page not to reload/refresh (which is why I think you're using axios) then you can either use TurboLinks or setup an SPA with VueRouter and load a view as a component

Hope this helps

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.