2017-04-12 3 views
0

Ich habe ein Problem mit meiner Laravel 5.3 mit Angular2 Webseite. Dieses Problem ist plötzlich aufgetreten.Laravel 5.3 mit Angular2 Fehler: XHR Fehler (404 nicht gefunden)

, dass der Fehler ist:

Error: Error: XHR error (404 Not Found) loading http://tricolores.app/main 
    at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://tricolores.app/zone.js/dist/zone.js:698:29) 
    at ZoneDelegate.invokeTask (http://tricolores.app/zone.js/dist/zone.js:265:35) 
    at Zone.runTask (http://tricolores.app/zone.js/dist/zone.js:154:47) 
    at XMLHttpRequest.ZoneTask.invoke (http://tricolores.app/zone.js/dist/zone.js:335:33) 
    Error loading http://tricolores.app/main 

SystemJs.config.js:

/** 
* System configuration for Angular samples 
* Adjust as necessary for your application needs. 
*/ 
(function (global) { 
    System.config({ 
     paths: { 
      // paths serve as alias 
      'npm:': 'node_modules/' 
     }, 

     // map tells the System loader where to look for things 
     map: { 
      // our app is within the app folder 
      app: 'app', 

      "rxjs": "node_modules/rxjs", 
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 

      // angular testing umd bundles 
      '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', 
      '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', 
      '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js', 
      '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js', 
      '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', 
      '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js', 
      '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js', 
      '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js', 
     }, 
     // packages tells the System loader how to load when no filename and/or no extension 
     packages: { 
      app: { 
       main: './main.js', 
       defaultExtension: 'js' 
      }, 
      rxjs: { 
       defaultExtension: 'js' 
      }, 
      'angular2-in-memory-web-api': { 
       main: './index.js', 
       defaultExtension: 'js' 
      } 
     } 
    }); 
})(this); 

TSconfig:

"compilerOptions":{ 
"declaration": false, 
"emitDecoratorMetadata": true, 
"experimentalDecorators": true, 
"mapRoot": "./", 
"module": "es6", 
"moduleResolution": "node", 
"noEmitOnError": true, 
"noImplicitAny": false, 
"outDir": "../dist", 
"sourceMap": true, 
"target": "es6", 
"typeRoots": [ 
"../node_modules/@types" 
], 
"types": [ 
"core-js" 
] 
} 

ich mein Paket-Abhängigkeiten sind auch okay ... haben Alle Abhängigkeiten korrekt importiert

Die erste Seite sieht wie folgt aus:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    {{--<link rel="stylesheet" href="assets/css/style.light-blue-500.min.css" />--}} 

    <title>Laravel 5.3 - Angular 2</title> 

    <!-- 1. Load libraries --> 
    <!-- Polyfill(s) for older browsers --> 
    {{ Html::script('core-js/client/shim.min.js') }} 
    {{ Html::script('zone.js/dist/zone.js') }} 
    {{ Html::script('reflect-metadata/Reflect.js') }} 
    {{ Html::script('systemjs/dist/system.src.js') }} 
    {{ Html::script('systemjs.config.js') }} 

    <script> 
     System.import('main').catch(function (err) { console.error(err); }); 
    </script> 
</head> 
<!-- 3. Display the application --> 
<body> 
<my-app>Loading...</my-app> 
</body> 
</html> 

Die erste Seite:

welcome.blade.php

Mit dem Start der App, die folgende Route aufgerufen.

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

Vielen Dank für Ihre Hilfe :)

Antwort

0

Das Problem ist, dass Sie http://tricolores.app/main 'nennen, aber sie haben keinen Weg für sie in Ihrem Laravel Back-End. Der einzige Weg (das wir sehen können) haben Sie ist die Wurzel oder 'http://tricolores.app'

Error: Error: XHR error (404 Not Found) loading http://tricolores.app/main 
    at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://tricolores.app/zone.js/dist/zone.js:698:29) 
    at ZoneDelegate.invokeTask (http://tricolores.app/zone.js/dist/zone.js:265:35) 
    at Zone.runTask (http://tricolores.app/zone.js/dist/zone.js:154:47) 
    at XMLHttpRequest.ZoneTask.invoke (http://tricolores.app/zone.js/dist/zone.js:335:33) 
    Error loading http://tricolores.app/main 

Laravel Routen jetzt

Route::get('/', function() { 
     return view('welcome'); 
    }); 

das Bearbeiten nächste Route & Fügen Sie den Dateipfad

Route::get('/main', function() { 
    //PDF file that is stored under project/public/download/info.pdf 
    $file= public_path(). "/download/info.pdf"; 

    $headers = array(
      'Content-Type: application/pdf', 
     ); 

    return Response::download($file, 'filename.pdf', $headers); 
} 

Stackoverflow source

+0

Wie kann ich eine Route erstellen, die die Datei zurückgibt? –

+0

Ich habe gerade meine Antwort mit einer Beispielroute zum Herunterladen einer PDF-Datei bearbeitet – VikingCode

+0

Ja danke .. Aber das ist nicht das Problem .. Ich weiß nicht, was Traceur Route zurückgeben sollte .. –

Verwandte Themen