3
我正在开发第一个NodeJs + Angular 2项目。在我以前使用这些路线的项目中,没有使用Angular2,它工作得很好。使用Angular 2的NodeJs路由目录rc.5
我在访问NodeJs中的多级目录路由时出错。
例子:
它的工作原理是这样的:
app.get('/dashboard', dashboard.getHome); // works
app.get('/user', user.getUser); // works
相反的:
app.get('/dashboard/home', dashboard.getHome); // won't work
app.get('/user/home', user.getUser); // won't work
我明白有Angular2路由一起工作,但反正是有直接访问到我在NodeJs中指定的静态URL?
/dashboard/tasks/42
我不能现在就这样做,这就是我与挣扎的问题:
,如果我想获得超过1级就像我会得到错误。
app.js
var main = require('./routes/index');
var dashboard = require('./routes/dashboard');
var user = require('./routes/user');
app.get('/', main.index);
app.get('/dashboard', dashboard.getHome); // works
// app.get('/dashboard/home', dashboard.getHome); // won't work this way
app.get('/user', user.getUser); // works
// app.get('/user/home', user.getUser); // won't work this way
仪表板/ index.html的
<html>
<head>
<title>Teamo - Dashboard</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="javascripts/core-js/client/shim.min.js"></script>
<script src="javascripts/zone.js/dist/zone.js"></script>
<script src="javascripts/reflect-metadata/Reflect.js"></script>
<script src="javascripts/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.8/socket.io.min.js"></script>
<script>
System.import('app/dashboard/dashboard').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-dashboard>Loading...</my-dashboard>
</body>
它不会使用这个网址,即使我已经设置在下方的路线工作app.js:
localhost:3000/dashboard/home
它返回下面的错误。
错误:
GET http://localhost:3000/dashboard/javascripts/core-js/client/shim.min.js
GET http://localhost:3000/dashboard/javascripts/zone.js/dist/zone.js
GET http://localhost:3000/dashboard/javascripts/reflect-metadata/Reflect.js
GET http://localhost:3000/dashboard/javascripts/systemjs/dist/system.src.js
GET http://localhost:3000/dashboard/systemjs.config.js
GET http://localhost:3000/dashboard/js/pace.min.js
Uncaught ReferenceError: System is not defined(anonymous function) @ home:18
GET http://localhost:3000/dashboard/js/pace.min.js
favicon.ico:1 GET http://localhost:3000/favicon.ico 500 (Internal Server Error)
对不起,也许我不清楚我的问题。我用更多的细节编辑了我的问题。我实际面临的问题是我无法拥有超过1级的路线,例如我只能通过'localhost:3000/dashboard'而不是'localhost:3000/dashboard/tasks/42'访问路线。 我无法访问比'localhost:3000/dashboard'更深的内容。 – Danzeeeee
@Danzeeeee但你是否尝试过改变元素的顺序,以便在子目录之后设置父目录? – 2016-08-16 07:35:22
是的,我试过但没有运气。 – Danzeeeee