简体   繁体   English

在路由到Meteor主页之前创建登录/注册页面?

[英]Create login/signup page before routing to main page in Meteor?

I have a global route that uses layout.html which specifies the header.html. 我有一个使用layout.html的全局路由,该路由指定了header.html。 I would like to know how to: 我想知道如何:

1) have a main landing page for login/sign up with the proper formatting, without the header. 1)有一个用于登录/注册的主登陆页面,格式正确,没有标题。 (Im using UserAccounts from Atmosphere but formatting is different, not sure why). (我使用的是来自Atmosphere的UserAccounts,但格式不同,不确定原因)。 Also the header in layout.js cannot be removed. 此外,layout.js中的标头也无法删除。

2) Upon login/sign in, it should go to main page. 2)登录/登录后,应转到主页。

Can someone advise how ? 有人可以建议吗?

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


This is the layout.html defined globally. 这是全局定义的layout.html。

<template name="layout">
  <div class="container">
    {{> header}}
    {{> errors}}

    <div id="main">
      {{> yield}}
    </div>
  </div>
</template>

Update after @Chase's suggestion. @Chase的建议后进行更新。 - It works on the routing and header is gone. -它适用于路由,标头不见了。 - Formatting is different from the website though. -格式与网站不同。

What I have is shown below while its supposed to look like http://useraccounts.meteor.com/ 下面显示了我所拥有的内容,而该内容看起来应该像http://useraccounts.meteor.com/ 在此处输入图片说明

You can create 2 diferents layouts templates with different setup. 您可以使用不同的设置创建2个不同布局模板。

Javascript Java脚本

Router.configure({
      layoutTemplate: 'adminLayout', //layout without header
   });

Router.route('/', { //main page, different layout
     layout:layout,
     name: 'auth'
  });

HTML 的HTML

<template name="adminLayout">
  <div class="container">
    {{> errors}}
    <div id="main">
      {{> yield}}
    </div>
  </div>
</template>

With this you will have diferents layouts, to diferentes routes. 这样,您将具有不同的布局,以区分路线。

Using this set up you won't need to set the layout with header for every route. 使用此设置,您无需为每个路线都设置带有标题的布局。

The User Accounts package has a Iron Router plugin to ensure the user is signed in that I use ( more info ). User Accounts程序包具有Iron Router插件,以确保用户使用我的身份登录( 更多信息 )。 I also configure routes supplied by the User Accounts package ( more info ) so I can directly route to a User Accounts sign up page. 我还配置了“用户帐户”包提供的路由( 更多信息 ),因此我可以直接路由到“用户帐户”注册页面。

Javascript 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 的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM