我正在尝试使用 angular.js 围绕 /parent root 进行路由,如果我使用锚链接等,则该路由有效(又名纯粹从角度处理的路由。例如,具有“/parent/createstudent”的 href 的链接可以工作但是,当我在网址栏中输入此内容或当它已位于该位置时刷新它时,它会生成错误,因为后端路由尚未完成。
因此,我在express中尝试了一个包罗万象的路由('/parent/*'),但这导致了一个错误,我的所有js和css都没有被读取。有谁知道如何解决这个问题?
我的静态文件目录
public
-> javascripts
-> app.js
-> angular.js
-> stylesheets
-> images
Error:
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/jquery.js". home:1
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/angular.js". home:1
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost:3000/parent/javascripts/main.js". home:1
Uncaught SyntaxError: Unexpected token < jquery.js:1
Uncaught SyntaxError: Unexpected token < angular.js:1
Uncaught SyntaxError: Unexpected token <
Express
app.get('/parent', function(req, res) {
res.render('main')
});
app.get('/parent/*', function(req, res) {
res.render('main')
});
角度路由(我在视图本身中声明控制器)
var app = angular.module('app', []).config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when('/parent/login',
{
templateUrl: '../templates/login.html'
}).
when('/parent/home',
{
templateUrl: '../templates/home.html'
}).
otherwise(
{
redirectTo: '/parent'
})
})