রাউটিং - Routing

Official Router

For most Single Page Applications, it’s recommended to use the officially-supported vue-router library. For more details, see vue-router’s documentation.

Available Router Methods

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
Route::get('/', '[email protected]');
Route::resource('posts', 'PostController');
Route::post('comments/{post_id}', ['uses' => '[email protected]', 'as' => 'comments.store']);
Route::get('comments/{id}/edit', ['uses' => '[email protected]', 'as' => 'comments.edit']);
Route::put('comments/{id}', ['uses' => '[email protected]', 'as' => 'comments.update']);
Route::delete('comments/{id}', ['uses' => '[email protected]', 'as' => 'comments.destroy']);
Route::get('comments/{id}/delete', ['uses' => '[email protected]', 'as' => 'comments.delete']);
Route::resource('categories', 'CategoryController', ['except' => ['create']]);
Route::get('blog/{slug}', ['as' => 'blog.single', 'uses' => '[email protected]'])->where('slug', '[\w\d\-\_]+');
Route::group(['middleware' => 'auth'], function () {
Route::get('/', function () {
// Uses Auth Middleware
});
Route::get('user/profile', function () {
// Uses Auth Middleware
});
});
Route::prefix('admin')->group(function() {
Route::get('/login', 'Auth\[email protected]')->name('admin.login');
Route::post('/login', 'Auth\[email protected]')->name('admin.login.submit');
Route::get('/', '[email protected]')->name('admin.dashboard');
});

If you just need very simple routing and do not wish to involve a full-featured router library, you can do so by dynamically rendering a page-level component like this:

const NotFound = { template: '<p>Page not found</p>' }
const Home = { template: '<p>home page</p>' }
const About = { template: '<p>about page</p>' }
const routes = {
'/': Home,
'/about': About
}
new Vue({
el: '#app',
data: {
currentRoute: window.location.pathname
},
computed: {
ViewComponent () {
return routes[this.currentRoute] || NotFound
}
},
render (h) { return h(this.ViewComponent) }
})

Combined with the HTML5 History API, you can build a very basic but fully-functional client-side router. To see that in practice, check out this example app.

Integrating 3rd-Party Routers

If there’s a 3rd-party router you prefer to use, such as Page.js or Director, integration is similarly easy. Here’s a complete example using Page.js.