我正在尝试用 Angular 制作一个简单的应用程序,与 Laravel 5 集成,并在路由应用程序 View 时遇到问题。
Routes.php
如下所示:
<?php
Route::get('/', function () {
return view('index');
});
在 Routes.php 中,我仅在应用程序加载时第一次处理。
But after that i want to handle all routing by Angular. So, i did like this:
app.js
文件
var membershipModule = angular.module('membershipModule', ['ngMaterial','ngRoute']);
membershipModule.config(function($routeProvider, $locationProvider, $mdThemingProvider){
$mdThemingProvider.theme('default').primaryPalette().accentPalette('blue-grey');
$routeProvider
.when('/login', {
controller: 'LoginController',
templateUrl: 'views/login.html'
})
.when('/register', {
controller: 'RegisterController',
templateUrl: 'views/register.html'
})
.otherwise({redirectTo: "/"});
$locationProvider.hashPrefix('');
});
但是当我访问 http://localhost:8000/#/login
时,它会抛出找不到 views/login.html
的错误。
- 我尝试在 Laravel 默认文件夹中制作
login.html
,如下图所示
- 还尝试在根目录中制作
views/login.html
,如下所示
但都不起作用
最佳答案
您可以将此文件放入公共(public)目录中。正如您在 https://laravel.com/docs/5.3/structure#the-public-directory 中看到的那样
关于php - Angular 和 Laravel 之间的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41484457/