gpt4 book ai didi

javascript - angular.js 和 express 的路由错误

转载 作者:搜寻专家 更新时间:2023-11-01 04:44:45 25 4
gpt4 key购买 nike

我正在尝试使用 angular.js 围绕/parent root 进行路由,如果我使用 anchor 链接等(也就是纯粹从 angular 处理的路由。例如,一个 href 为 '/parent/的链接createstudent' 有效。但是,当我在 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 <

express

app.get('/parent', function(req, res) {
res.render('main')
});
app.get('/parent/*', function(req, res) {
res.render('main')
});

Angular 路由(我在 View 本身中声明 Controller )

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'
})
})

最佳答案

这是新引入的“行为改变”(或错误)。

尝试使用基本标签:

<base href="/" />

关于javascript - angular.js 和 express 的路由错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16999367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com