2016-08-16 10 views
3

私はNodeJs + Angular 2プロジェクトに取り組んでいます。このようなルートの私の以前のプロジェクトではAngular2なしで完璧に動作しました。NodeJsルーティングディレクトリ、角2 rc5

NodeJsのマルチレベルディレクトリルーティングにアクセスする際にエラーが発生しました。

例:私はで動作するようにAngular2ルーティングがあります理解

app.get('/dashboard/home', dashboard.getHome); // won't work 
app.get('/user/home', user.getUser);    // won't work 

が、直接にアクセスするためにとにかくがある:

app.get('/dashboard', dashboard.getHome);  // works 
app.get('/user', user.getUser);     // works 

の代わりに:

それはこのように動作しますNodeJsで指定した静的URLですか?

私は私が1つの以上のレベルのようなアクセスをしたい場合は、エラーを取得します:

/dashboard/tasks/42 

私は今それを行うことができないんだけど、それは私が苦労してる問題です。

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> 

それは私が下記のルートを設定している場合でも、このURLを使用して動作しません。アプリ.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) 

答えて

0

変更要素の順序:

app.get('/dashboard', dashboard.getHome);  // works 
app.get('/dashboard/home', dashboard.getHome); // won't work 

へ:

app.get('/dashboard/home', dashboard.getHome); // won't work 
    app.get('/dashboard', dashboard.getHome);  // works 

Expressは順番に敏感です。

+0

ご迷惑をおかけして申し訳ございません。私はより詳細な質問を編集しました。私が実際に直面している問題は、「localhost:3000/dashboard/tasks/42」ではなく、「localhost:3000/dashboard」でルートにアクセスできるような1レベル以上のルートを持つことができないということです。 「localhost:3000/dashboard」より深くはアクセスできませんでした。 – Danzeeeee

+0

@Danzeeeeeしかし、サブディレクトリの後に親ディレクトリが設定されるように要素の順序を変更しようとしましたか? –

+0

はい、私は運を試みましたが運がありません。 – Danzeeeee