Laravel 7 + Vue.js 报错:View [app] not found 求助
Hey there, let's sort out this frustrating error you're hitting! The core issue here is pretty straightforward once you connect your code to your file structure.
Why You're Seeing This Error
In your web.php route, you're telling Laravel to load the app view:
Route::get('{any}', function () { return view('app'); })->where('any', '.*');
But right now, the only blade view file you have in resources/views is welcome.blade.php — Laravel can't find a file named app.blade.php, hence the "View [app] not found" message.
Two Simple Fixes
You have two options to resolve this, depending on your project's needs:
Option 1: Update the Route to Use Your Existing View
If you want to keep using welcome.blade.php as your entry point, just adjust the view name in your route to match the file you already have:
Route::get('{any}', function () { return view('welcome'); })->where('any', '.*');
This will make Laravel load your existing welcome.blade.php instead of searching for a non-existent file.
Option 2: Create the Missing app.blade.php File
Since you're using Vue.js (likely for a single-page app), it's standard practice to have a dedicated app.blade.php as your SPA entry. Here's how to set this up:
- In your
resources/viewsfolder, create a new file namedapp.blade.php - Add a basic structure (you can reuse content from
welcome.blade.phpand tweak it for your SPA):
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Your Laravel + Vue App</title> <!-- Load compiled Vue assets (run npm run dev/prod first!) --> <link href="{{ mix('css/app.css') }}" rel="stylesheet"> </head> <body> <!-- This is where your Vue app will mount --> <div id="app"></div> <script src="{{ mix('js/app.js') }}"></script> </body> </html>
- Compile your Vue assets to make sure everything loads correctly:
npm run dev
Or for production-ready assets:
npm run prod
Quick Double-Check
Make sure your view files live directly in the resources/views/ directory — Laravel doesn't look elsewhere for blade views by default. Also, note that on Linux/macOS, filenames are case-sensitive, so app.blade.php needs to be spelled exactly as you reference it in the route.
内容的提问来源于stack exchange,提问作者hari dran

