【发布时间】:2013-06-08 12:05:52
【问题描述】:
我正在尝试使用 angular.js 围绕 /parent 根进行路由,如果我使用锚链接等(也就是纯粹从 angular 处理的路由。例如,href 为 '/parent/ 的链接) createdtudent' 有效。但是,当我在 url 栏中键入它或当它已经在该位置时刷新它时,它会生成一个错误,因为后端路由尚未完成。
因此,我在 express 中尝试了一个包罗万象的路由('/parent/*'),但这会导致我的所有 js 和 css 都没有被读取的错误。有谁知道如何解决这个问题?
我的静态文件目录
public
-> javascripts
-> app.js
-> angular.js
-> stylesheets
-> images
错误:
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 <
快递
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'
})
})
【问题讨论】:
标签: javascript angularjs express