meteor项目重建 关于No route definitions found.

因为meteor版本升级问题,1.7版本与1.6版本使用方法有所不同,一些朋友在使用1.7版本的meteor创建项目的时候,发现使用

iron:router路由模块的时候,入坑了,页面一直提醒以下标识,并无法使用路由,本人也是入坑了,在此,仅以此篇文章介绍此问题,希望与各位共同进步。

iron:router

No route definitions found.

meteor项目重建

1.在cmd使用以下命令创建一个meteor项目

meteor create myApp

2.进入myAPP

cd meteor

3. 启动meteor

meteor

=================================================================

设置路由

1.在cmd的myAPP路径下安装iron:router模块

meteor add iron:router

2.在项目根目录下添加lib文件夹

3.在lib中添加router文件夹

4.增加router.js

运行项目,有的会出现以下问题

解决方案如下,在router.js添加以下代码

============router.js=======================
Router.configure({
    notFoundTemplate: "DataNotFound",
    layoutTemplate: "layout",
    loadingTemplate: 'Loading'
});

Router.route('/', {
    layoutTemplate: 'layoutFull',
    name:'index1'
});

Router.route('/test', {
    layoutTemplate: 'layoutFull',
    action() {
        this.render('test');
    },
});

由于在此router.js中引用了layoutFull.html;loading.html;loading.js;故增加此三个模板,即可解决此问题

===========layoutFull.html=======================
<template name="layoutFull">
    {{> yield}}
</template>


============loading.html=========================
<template name="Loading">
    
</template>

===========loading.js===========================
Template.Loading.onCreated(function(){
    $.showLoading();
});

Template.Loading.onDestroyed(function(){
    $.hideLoading();
});

猜你喜欢

转载自blog.csdn.net/Long861774/article/details/82590879