无法加载带有laravel 5和angularjs的任何模板
我无法使用angularjs使用无法加载带有laravel 5和angularjs的任何模板,angularjs,laravel-5,angular-ui-router,Angularjs,Laravel 5,Angular Ui Router,我无法使用angularjs使用$stateProvider或$routeProvider或任何地方加载一些模板以“/”索引laravel 5 route index.blade.php的内容很好,每次我直接在web浏览器上访问模板的URL时,一切都很好 问题是angularjs的负载。开发人员控制台上存在此错误: Error: [$compile:tpload] Failed to load template: /templates/site/home (HTTP status: undefi
$stateProvider
或$routeProvider
或任何地方加载一些模板以“/”索引laravel 5 route
index.blade.php的内容很好,每次我直接在web浏览器上访问模板的URL时,一切都很好
问题是angularjs的负载。开发人员控制台上存在此错误:
Error: [$compile:tpload] Failed to load template: /templates/site/home (HTTP status: undefined undefined)
因此,我使用{path?}
和路由::any()
定制了我的laravel路由
我使用模板
作为前缀,但实际上并不存在。这是要利用的laravel路由的唯一虚拟url
这一执行情况如下:
web.php
<?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::group(['prefix' => 'panel'], function () {
Route::any('{path?}', function () {
return view('panel/index');
})->where('path', '.+');
});
Route::group(['prefix' => 'templates'], function () {
Route::any('{path?}', function ($name) {
dd($name);
return view($name);
})->where('path', '.+');
});
Route::group(['prefix' => ''], function () {
Route::any('{path?}', function () {
return view('site/index');
})->where('path', '.+');
});
所以
我不理解刚刚推出的panel
route中的模板发生了什么
在这里,一切都很好
在这里,一切都很好
在这里,一切都很好
更新
我在这里找到了解决办法
经过一些测试后,我意识到HTTP请求拦截器被阻止,$templateCache无法正常工作
在向拦截器添加一个异常(这样它就可以忽略进入模板缓存的“请求”)之后,一切正常
拦截器代码:
request: function (config) {
config.headers = config.headers || {};
if (config.url.startsWith("/templates/")) {
//Not modifying requests to these urls,
//as they are angular template cache requests
return config;
}
//Do the interceptor work here. Add headers or whatever.
return config;
$httpProvider
拦截器导致了此问题。我在这两个链接上找到了解决方案:$httpProvider
拦截器导致了这个问题。最后,我在这两个链接上找到了解决方案:和
request: function (config) {
config.headers = config.headers || {};
if (config.url.startsWith("/templates/")) {
//Not modifying requests to these urls,
//as they are angular template cache requests
return config;
}
//Do the interceptor work here. Add headers or whatever.
return config;