2016-08-30 3 views
1

フロールータパッケージの助けを借りてルーティングを適用しようとしています。しかし、それは私が期待していたものとして私のために働いていません。私は自分のコードを共有します、私が間違っている場所を教えてください!前もって感謝します。FlowRouterの助けを借りて流星が私のために働いていない

FlowRouter.route('/',{ 
    name:'home', 
    action(){ 
      BlazeLayout.render("HomeLayout"); 
    } 
}); 

FlowRouter.route('/test',{ 
    name:'test', 
    action(){ 
     BlazeLayout.render('MainLayout',{main:'Test'}); 
    } 
}); 

localhost:3000/testにアクセスすると、次のエラーが発生します。

modules-runtime.js:36Uncaught Error: Cannot find module './main.html' 

Exception in defer callback: Error: Expected template or null, found: undefined 
at ._render (http://localhost:3000/packages/spacebars.js?hash=65db8b6a8e3fca189b416de702967b1cb83d57d5:61:13) 
at doRender (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2027:25) 
at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1875:20 
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:3687:12) 
at http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1873:29 
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:2214:12) 
at viewAutorun (http://localhost:3000/packages/blaze.js?hash=ef41aed769a8945fc99ac4954e8c9ec157a88cea:1872:18) 
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:339:36) 
at new Tracker.Computation (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:229:10) 
at Object.Tracker.autorun (http://localhost:3000/packages/tracker.js?hash=f525263111eb9d90f4ce1ad064f97aca4a6c1b07:604:11) 

私が間違っているところを教えてください。コードに変更を加える必要がありますか?

は、ここに私のindex.htmlファイルのコードです:

<head> 
    <title>intermediate-meteor</title> 
</head> 

ここに私のMainLayout.htmlである:ここでは

<template name="MainLayout"> 
    <header> 
     <h1>My Recipe Book</h1> 
    </header> 
    <main> 
     {{>Template.dyanamic template=main}} 
    </main> 
</template> 

<template name="Test"> 
    <h1>Test Template Rendering form Main Template...!!</h1> 
</template> 

私HomeLayout.htmlです:

<template name="HomeLayout"> 
    <header> 
     <h1>My Recipe Book</h1> 
    </header> 
    <main> 
     <div class="billboard"> 
      <h2>Organize your meals</h2> 
     </div> 
    </main> 
</template> 

パッケージ。 jasonファイルコード:

# Meteor packages used by this project, one per line. 
# Check this file (and the other files in this directory) into your repository. 
# 
# 'meteor add' and 'meteor remove' will edit this file for you, 
# but you can also edit it by hand. 

[email protected]    # Packages every Meteor app needs to have 
[email protected]  # Packages for a great mobile UX 
[email protected]     # The database Meteor supports right now 
[email protected] # Compile .html files into Meteor Blaze views 
[email protected]   # Reactive variable for tracker 
[email protected]     # Helpful client-side library 
[email protected]     # Meteor's client-side reactive programming library 

[email protected] # CSS minifier run for production mode 
[email protected] # JS minifier run for production mode 
[email protected]    # ECMAScript 5 compatibility for older browsers. 
[email protected]    # Enable ECMAScript2015+ syntax in app code 
[email protected]   # Server-side component of the `meteor shell` command 



kadira:flow-router 
kadira:blaze-layout 

私のコードを見て、どこに間違いをしているのか教えてください。そして、あなたがルートにどのようなURLからロードされるどのようなテンプレートを制御できindex.html

<head> 
    <title>intermediate-meteor</title> 
</head> 
<body> 
    {{> layout}} 
</body> 

<template name="layout"> 
    {{> Template.dynamic template=main}} 
</template> 

答えて

1

あなたindex.htmlファイルには、動的なテンプレートを必要とするものです。


だから、最後に、あなたのルートは次のようになります。私はその後

<body> 
    {{> layout}} 
</body> 

<template name="layout"> 
    {{> Template.dynamic template=main}} 
</template> 

FlowRouter.route('/', { 
    action: function() { 
    BlazeLayout.render('layout', { main: 'MainLayout' }); 
    } 
}); 

FlowRouter.route('/test', { 
    action: function() { 
    BlazeLayout.render('layout', { main: 'Test' }); 
    } 
}); 

FlowRouter.route('/home', { 
    action: function() { 
    BlazeLayout.render('layout', { main: 'HomeLayout' }); 
    } 
}); 

私は本体のみのテンプレートを読み込むindex.htmlファイルと私のHTMLを設定していますテンプレートごとに新しいHTMLファイルを作成します。test.html

<template name="test"> 
    <h1>Hello, this is a test page</h1> 
</template> 

そしてもちろん、別のファイルでのごhomelayoutテンプレート:homelayout.html

<template name="homelayout"> 
    <h1>Hello, this is the home page</h1> 
</template> 
+0

私はメインテンプレートであるMainLayout.htmlを作成しました。私はHomeLayout.htmlを作成しました。そして、私は "Test"という名前でMainLayout.htmlのテンプレートを作成し、私が使用しているフロールートに従ってroute.jsでルーティングするコードを記述するためにindex.htmlを持っています私のプロジェクトでは、それは私が望むように私のために働いていない..!完了したコードを共有できますか?申し訳ありませんが、私はまだ流星に慣れていないので、私はどこに間違っているのか分かりません。 –

+0

また、「install.js:101Uncaught Error:モジュール './main.html'を見つけることができません」というエラーが表示されます。私のミスはどこですか? –

+0

'kadira:flow-router'と' kadira:blaze-layout'の両方がインストールされていますか?たぶんあなたのHTMLファイルをあなたのポストに追加して、それらを見ることができます。 – gkrizek

0

あなたがデフォルトのクライアント/ main.htmlとファイルを削除しているようです。 client/main.jsの "import" ./main.html '"行を更新しましたか?

+0

ファイルの名前をmian.htmlからindex.htmlに変更するだけです。 –

+0

私はMeteorも習っていますが、FlowRouterのドキュメントを読んでいません。ファイル名をmain.htmlからindex.htmlに変更した場合は?クライアント/ main.jsの内部で同じことをしましたか? – Khai

+0

いいえ。私はmeteor jsのチュートリアルを学習しています。私はMeteor jsを学ぶためのレベルアップの中間チュートリアルに従います。そのチュートリアルでは、 "MainLayout.html"や "HomeLayout.html"のような2つのレイアウトを作成した後、MainLayout、htmlでテストテンプレートを作成し、フローラを使ってそのテンプレートにアクセスしますが、そうではありません。私はあなたがそれを見ることができるリンクを共有し、それが可能であることを教えてくれるでしょう。どうもありがとうございました。 リンクは次のとおりです: - https://www.youtube.com/watch?v=nOJ0hfVo368&index=6&list=PLLnpHn493BHFYZUSK62aVycgcAouqBt7V –

関連する問題