路由器没有发生在铁路由器中

时间:2014-05-28 12:47:24

标签: meteor

I have updated meteor project to 0.8.0 and have installed iron-router package. Did everything that is required but routing not happening. It is showing the front page i.e I am able to login into the application. But after that not able to go to any of the pages. My homepage have so many buttons as can be seen in header.html file. When I clicked on grumble link, in url it is displaying that "localhost:3000/grumble". But nothing is getting displayed on that form.

- >我的router.js页面是:

Router.configure({

    layoutTemplate: 'layout'
});

Router.map(function() {
    this.route('issues', {path:'/'});
    this.route('issues', {path:'/issues'});
    this.route('closedIssues', {path:'/closedIssues'});
    this.route('subscribedKeywords', {path:'/subscribedKeywords'});
    //this.route('grumble');
    //this.route('grumble2');

    this.route('grumble', {path:'grumble'});
    this.route('grumble2', {path:'grumble2'});

    this.route('issuePage', {

        path:'/issues/:_id',
        data: function() {Session.set('currentIssueId', this.params); }
    });

    this.route('closedIssuePage', {

        path:'/closedIssues/:_id',
        data: function() { Session.set('currentClosedIssueId', this.params); }
    });
});


var requireLogin = function() {
    if ( Meteor.user()) 
        this.render(this.params);
    else if (Meteor.loggingIn())
        this.render('loading');
    else
        this.render('accessDenied');


        this.stop();

}

var clearErrors = function() {
    clearErrors();
    this.render(this.params);

    this.stop();

} 

Router.onBeforeAction(requireLogin, {only: 'grumble'});
Router.onBeforeAction(clearErrors);

- > Header.html文件来自grumble.html,此页面中称为meas href,用于传输控件:

<template name="header">
    <header class="navbar">
    <p>inside header.html</p>
        <div class="navbar-inner">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-coll
        apse">
            </a>
            <a class="details btn" href="{{pathFor 'grumble'}}">Grumble</a>
            {{#if currentUser}}
                    <a class="details btn" href="{{issuesPath}}">See Issues</a>
                    <a class="details btn" href="{{closedIssuesPath}}">Closed Issues</a>
                    <a class="details btn" href="{{subscribedKeywordsPath}}">Watchlist</a>
                    {{> notifications}}

            {{/if}}
            <span class="nav pull-right">
                <li>{{> loginButtons}}</li>   <!--should be {{> }} here in order to display login functionality-->
            </span>
        </div>
    </header>
</template>

- &GT; Grumble.html,应该转移控件的文件意味着已经为此页面进行了路由以获得控件

<template name="grumble">
<p>inside form i.e. grumble.html</p>
    <form class="main">
        <fieldset>
            <legend>New Grumble</legend>
                <table border="0">
                    <tr>
                        <td>
                            <label class="control-label" for="shortdesc"><span style="color:red;">*</span>&nbsp;    Description</label>
                            <input name="shortdesc" type="text" value="" placeholder="Radiator not working"/>
                        </td>
                        <td>
                            <label class="control-label" for="urgency">Urgency</label>
                            <select name="urgency" >
                                <option value="high">High</option>
                                <option value="medium">Medium</option>
                                <option value="low">Low</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="control-label" for="date">Date</label>
                            <input name="date" type="date" value="{{date}}" />
                        </td>
                        <td>
                            <label class="control-label" for="time">Time</label>
                            <input name="time" type="time" value="{{time}}" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="control-label" for="dept">Department/Building</label>
                            <input name="dept" type="text" value="" placeholder="Physiotherapy"/>
                        </td>
                        <td>
                            <label class="control-label" for="unit">Unit</label>
                            <input name="unit" type="text" value="" placeholder="Occupational Therapy"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="control-label" for="room">Room</label>
                            <input name="room" type="text" value="" placeholder="P2"/>
                        </td>
                        <td>
                            <label class="control-label" for="category">Category</label>
                            <input name="category" type="text" value="" placeholder="Utility"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label class="control-label" for="details">Details</label>
                            <textarea name="details" value="" placeholder="Broken radiator next to vending      machine."></textarea>
                        </td>
                        <td>
                            <label class="control-label" for="anonymous">Anonymity</label>
                            <select name="anonymous" >
                                <option value="anonymous">Anonymous</option>
                                <option value="identifiable">Identifiable</option>
                            </select>
                        </td>
                    </tr>
                </table>
                <div class="control-group">
                    <div class="controls">
                    <input type="submit" value="Submit" class="btn btn-primary"/>
                </div>
                </div>
            </fieldset>
        </form>
    </template> 

<template name="grumble2">
    <form class="main">
        <fieldset>
        <legend>New Grumble</legend>
            <table border="0">
                <tr>
                    <td>
                        <label class="control-label" for="details"><span style="color:red;">*</span>&nbsp;Description</label>
                        <textarea name="details" value="" placeholder="Broken radiator next to vending machine."></textarea>
                    </td>
                </tr>
            </table>
            <div class="control-group">
                <div class="controls">
                    <input type="submit" value="Submit" class="btn btn-primary"/>
                </div>
            </div>
        </fieldset>
    </form>
</template>

Please help me where I am wrong as have read the article : http://www.manuel-schoebel.com/blog/iron-router-tutorial. And tried to make changes but not working. Any pointers please.

2 个答案:

答案 0 :(得分:0)

我认为路由this.route('issues', {path:'/issues'});会覆盖路由this.route('issues', {path:'/'});(它们具有相同的名称!),因此您没有/的路由。尝试更改其中一个名称,看看是否有所不同。

答案 1 :(得分:0)

你错过了&#34; /&#34;在你抱怨的路线前面。它应该是this.route('grumble', {path:'/grumble'})