E
E
Emil Rakhmatullin2021-08-09 16:12:42
Laravel
Emil Rakhmatullin, 2021-08-09 16:12:42

What is the best way to implement Laravel and Vue Router routes?

Conditionally on Laravel, I write the path to the Vue application:

Route::group(['prefix' => 'users', 'middleware' => ['permission:users read']], function (){
    Route::get('/', '[email protected]');
    Route::get('create', '[email protected]');
    Route::get('edit/{id}', '[email protected]');
    Route::get('detail/{id}', '[email protected]');
});


vue router:
path: 'users',
    component: UsersComponent,
    meta: {
        breadcrumb: 'Пользователи',
    },
    children: [
        {
            path: '/',
            name: 'users.index',
            component: UsersIndex,
            meta: {
                breadcrumb: 'Все',
            },
        },
        {
            path: 'create',
            name: 'users.create',
            component: UserCreate,
            meta: {
                breadcrumb: 'Создать пользователя',
            },
        },
        {
            path: 'detail/:id',
            name: 'users.detail',
            component: UserDetail,
            meta: {
                breadcrumb: 'Детальная информация о пользователе',
            },
        },
        {
            path: 'edit/:id',
            name: 'users.edit',
            component: UserEdit,
            meta: {
                breadcrumb: 'Изменить пользователя',
            },
        },
    ]


How not to constantly specify the path in web.php on a Vue page, a la
Route::get('detail/{id}', '[email protected]');
?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-08-09
@delphinpro

Send all requests to one controller Clearly, in this case, you will not get 404 responses for any requests.
Route::fallback('[email protected]');

P
pLavrenov, 2021-08-10
@pLavrenov

Read what REST is and take common practices as a basis.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question