我有一个Meteor应用程序,我正在使用angular-meteor和Iron Router路由的组合。
Angular-meteor客户端路由用于所有浏览器端路由,Iron Router用于所有服务器端路由。我在Meteor中实现了一个OAuth2服务器,所以我需要能够在不使用客户端代码的情况下访问URL。
设置很好,但有一个后果: Iron Router 'not found‘模板总是显示在客户端,因为我没有Iron Router的客户端路由:

我还尝试在客户端代码中添加一个空白的Iron Router路由:
Router.route('(.*)', function(){
//Do nothing
});或
Router.route('(.*)', function(){
//Do nothing
this.ready();
});但这会导致我所有的angular-meteor模板都被复制到客户端上:

我还尝试将Iron Router配置设置为使用我在Blaze中编写的一个不同的not-found模板,并使用angular-with-blaze:
> meteor add angular-with-blaze客户端和服务器代码:
Router.configure({
notFoundTemplate: "ironrouternotfound"
});ironrouternotfound_blaze.html:
<template name="ironrouternotfound">
IR Not Found
</template>ironrouternotfound.html
<blaze-template name="ironrouternotfound"></blaze-template>但这会导致以下文本被注入到HTML DOM的底部:
Couldn't find a template named "ironrouternotfound" or "ironrouternotfound". Are you sure you defined it?此消息是由IronRouter注入的,它在div或任何CSS类中都没有ID,所以我不能使用JS或CSS隐藏它。(嗯,我也许能够破解JS来删除页面上的最后一个div,但这可能很危险)
在这种情况下,是否有人设法删除了Iron Router not-found视图?
发布于 2015-12-31 06:58:25
我的临时CSS技巧是:
div[style="margin: 0 auto; color: red;"] {
display: none;
}发布于 2017-02-17 07:58:44
这对我很有效。首先在客户端文件夹中声明一个空白HTML模板,如下所示:
<template name="noRoutesTemplate"></template>下一步在公共文件夹中(例如,‘'lib')将iron路由器的noRoutesTemplate添加到配置中。
import { Router } from 'meteor/iron:router';
Router.configure({
noRoutesTemplate: 'noRoutesTemplate',
});请参阅此参考link
https://stackoverflow.com/questions/34519752
复制相似问题