- Forums
- laravel
- How To Add A Simple Route To Laravel Blade Or React Inertia
this page contains the code to simply add a laravel route to web.php for blade or react inertia. [5301], Last Updated: Mon Jun 24, 2024
edw
Sun Mar 24, 2024
0 Comments
231 Visits
To add a simple route to a laravel project I will show you two options:
example.com/post
1. Laravel Blade:
web.php
Route::get('/post', function () {
return view('post');
});
resources/views/post.blade.php
<h1>This is post.blade.php</h1>
2. Laravel Inertia (React):
web.php (with login authentication)
Route::get('/post', function () {
return Inertia::render('Post');
})->middleware(['auth', 'verified'])->name('post');
resources/js/Pages/Post.jsx
import React from 'react';
function Post () {
return (
<div>
<h1>Post Component</h1>
</div>
)
}
export default Post