View Routes
Lendly has an About page. It is pure HTML: no database, no form, no logic. Writing a closure that only returns a view works, but it is three lines of ceremony around one idea. Laravel has a one-line shortcut for exactly this case.
The rule
No logic, just a page: use Route::view.
The long way:
Route::get('/about', function () {
return view('about');
});The short way does the same thing:
Route::view('/about', 'about');- First argument: the URI.
- Second argument: the view name, so
'about'meansresources/views/about.blade.php, and'pages.rules'meansresources/views/pages/rules.blade.php. - Optional third argument: an array of fixed data for the view.
Route::view('/rules', 'pages.rules', ['maxLoans' => 3]);Inside the view, {{ $maxLoans }} prints 3.
A view route answers GET (and HEAD) requests. It can be named and given middleware like any other route:
Route::view('/help', 'help')->name('help');What it cannot do is run code for this page. The data array is built when the routes file loads, not when someone visits the page, so it cannot depend on the request, the logged-in member or fresh database results.
The shortcut
Before writing a closure, ask "does this page need anything computed per request?" If no, use Route::view. If it needs a query, the current user, or input, use a closure or a controller.
About
Static text. Nothing computed.
Route::view('/about', 'about').
The trap is trying to squeeze logic into the data array, such as ['count' => Book::count()]. That query runs whenever the routes file loads, which slows down every page in the app, and once routes are cached the number is frozen at whatever it was when the cache was built.
Drills
Answer fast — trust the rule.
Which line shows resources/views/contact.blade.php at /contact?
Which Lendly page is a poor fit for Route::view?
What does the third argument in Route::view('/rules', 'rules', ['maxLoans' => 3]) do?
Can you chain ->name('about') onto a view route?
Remember
- No logic, just a page: use
Route::view. - Ask: anything computed per request? No → view route, yes → closure or controller.
- Trap: the data array is built when routes load, so never put queries in it.
