我有一个Meteor应用程序,我使用了角度流星和铁路由器路由的组合。
Angular-meteor客户端路由用于所有浏览器端路由,Iron Router用于所有服务器端路由。我在Meteor中实现了OAuth2服务器,因此我需要能够在不使用客户端代码的情况下访问URL。
设置效果很好,但结果却是:铁路由器未找到'模板总是在客户端上显示,因为我没有Iron Router的客户端路由:
我还尝试将空白铁路由器路由添加到客户端代码:
Router.route('(.*)', function(){
//Do nothing
});
或
Router.route('(.*)', function(){
//Do nothing
this.ready();
});
但这导致我的所有角度流星模板都在客户端上重复:
我还尝试将Iron Router配置设置为使用我在Blaze中编写的另一个未找到的模板,并使用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,但那可能很危险)
在这种情况下,是否有人设法删除了铁路由器未找到的视图?
答案 0 :(得分:0)
我的临时CSS黑客是:
div[style="margin: 0 auto; color: red;"] {
display: none;
}
答案 1 :(得分:0)
这对我有用。首先在客户端文件夹中声明一个空白的HTML模板,如下所示:
<template name="noRoutesTemplate"></template>
接下来在公共文件夹(例如'lib')中将铁路由器的noRoutesTemplate添加到配置中。
import { Router } from 'meteor/iron:router';
Router.configure({
noRoutesTemplate: 'noRoutesTemplate',
});
请参阅此参考link