[英]Create login/signup page before routing to main page in Meteor?
我有一個使用layout.html的全局路由,該路由指定了header.html。 我想知道如何:
1)有一個用於登錄/注冊的主登陸頁面,格式正確,沒有標題。 (我使用的是來自Atmosphere的UserAccounts,但格式不同,不確定原因)。 此外,layout.js中的標頭也無法刪除。
2)登錄/登錄后,應轉到主頁。
有人可以建議嗎?
Router.configure({
layoutTemplate: 'layout', //This is where header is specified globally
waitOn: function() {
return [Meteor.subscribe('notifications')]
}
});
Router.route('/', {
name: 'auth'
}); //added this new line
Router.route('/posts', {
name: 'home',
controller: NewPostsController
});
var requireLogin = function() {
if (! Meteor.user()) {
if (Meteor.loggingIn()) {
this.render(this.loadingTemplate);
} else {
this.render('accessDenied');
}
} else {
this.next();
}
}
Router.onBeforeAction('dataNotFound', {only: 'postPage'});
Router.onBeforeAction(requireLogin, {only: 'postSubmit'});
這是全局定義的layout.html。
<template name="layout">
<div class="container">
{{> header}}
{{> errors}}
<div id="main">
{{> yield}}
</div>
</div>
</template>
@Chase的建議后進行更新。 -它適用於路由,標頭不見了。 -格式與網站不同。
下面顯示了我所擁有的內容,而該內容看起來應該像http://useraccounts.meteor.com/
您可以使用不同的設置創建2個不同布局模板。
Java腳本
Router.configure({
layoutTemplate: 'adminLayout', //layout without header
});
Router.route('/', { //main page, different layout
layout:layout,
name: 'auth'
});
的HTML
<template name="adminLayout">
<div class="container">
{{> errors}}
<div id="main">
{{> yield}}
</div>
</div>
</template>
這樣,您將具有不同的布局,以區分路線。
使用此設置,您無需為每個路線都設置帶有標題的布局。
User Accounts程序包具有Iron Router插件,以確保用戶使用我的身份登錄( 更多信息 )。 我還配置了“用戶帳戶”包提供的路由( 更多信息 ),因此我可以直接路由到“用戶帳戶”注冊頁面。
Java腳本
Router.configure({
layoutTemplate: 'layout' //main layout with header
});
//Iron router plugin to ensure user is signed in
AccountsTemplates.configureRoute('ensureSignedIn', {
template: 'atTemplate', //template shown if user is not signed in
layoutTemplate: 'atLayout' //template for login, registration, etc
});
//Don't require user to be logged in for these routes
Router.plugin('ensureSignedIn', {
except: ['login', 'register']
});
//Configure route for login
AccountsTemplates.configureRoute('signIn', {
name: 'login',
path: '/login',
template: 'atTemplate',
layoutTemplate: 'atLayout',
redirect: '/'
});
//Configure route for registration
AccountsTemplates.configureRoute('signUp', {
name: 'register',
path: '/register',
template: 'atTemplate',
layoutTemplate: 'atLayout',
redirect: '/'
});
//Home page to show once logged in
Router.route('/', {
name: 'home',
action: function(){
this.render('home');
}
});
的HTML
<template name="layout">
<div class="container">
{{> header}}
{{> errors}}
<div id="main">
{{> yield}}
</div>
</div>
</template>
<template name="atLayout">
<div class="at-container">
{{> yield}}
</div>
</template>
<template name="atTemplate">
{{> atForm}}
</template>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.