首页 > 解决方案 > 路由参数传递错误:Laravel+Vue

问题描述

我正在使用Laravel 5.7Vue.js 2

我想测试 Vue.js 路由参数。但它不工作!

应用程序.js

import ProductDetails from './components/front/shop/ProductDetails'

const routes = [
{
    path: '/pds/:id',
    component: ProductDetails
}

产品详情.vue

<template>
    <h1>Book {{ $route.params.id }} </h1>
</template>

当我开始在localhost:8000/pds/1 Page not Found中进行测试时,即将到来。此错误所需的原因。

标签: laravellaravel-5vue.jsrouteslaravel-5.7

解决方案


您必须配置您的后端。看这里

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/{any}', 'SpaController@index')->where('any', '.*');

推荐阅读