Probably an issue of relative paths; how is the CSS and JS linked in the View (or Layout) template?
Blade and paths
Everything renders fine when displaying a page through a the following route:
Route::get('/blog', function () {
$post = // some logic
return view('blog', [
'posts' => $posts,
]);
})->name('blog'); // named route
But when I use another route for blog details, the page displays but is not properly rendered as it can't see the css and js files anymore:
Route::get('/blog/{id}/{slug}', function (string $id, string $slug) {
$post = // some logic
return view('blog', [
'post' => $post,
]);
})->name('blog'); // named route
What needs to be modified to have the website/postid/slug path and properly render the templates?
@Developer654079525 yes, so as mentioned above, you are using relative paths to the assets, but whenever there is more that one URL segment, it will fail. Instead use absolute paths to the assets, so they are resolved from the base URL of your application (note the leading / - this assumes the assets are in subdirectories of the public directory:
<link rel="stylesheet" href="/css/style.css" />
<script src="/js/app.js"></script>
Please or to participate in this conversation.