Iron Router(流星):如何设置默认路由?
Iron Router (meteor): how to set default route?
我有 4 个视图(模板):
- 开始
- showScannedData
- 仪表板
- 加载中
我在client_server/lib/routing.js中定义了路由:
Router.configure({
loadingTemplate: 'loading'
});
Router.route('/', {
name:'start',
template:'start'
});
Router.route('/mobile', {
name:'mobileStart',
template:'showScannedData'
});
Router.route('/desktop', {
name:'desktopStart',
template:'dashboard'
});
在client/app.js中我输入:
Router.go('/start');
有效。然而,模板 showScannedData 被渲染了两次,就好像我也将它设置为 templateLayout 一样。
至于我的应用程序 我不需要默认布局 但单个个人视图可以在开始时加载(模板:开始)或用户执行的特定操作(模板:showScannedData /仪表板)。
我做错了什么?
感谢@piscator 和@Keith 给我关键提示。
我发现,虽然我没有两次渲染模板,但我把
{{>> showScannedData}}
在project_name.html文件中(即不使用路由时渲染的文件)
所以我基本上从文件中删除了上面的行,并使用 Iron 的路由器通过以下方式转到入门模板:
Router.go("/")
在client/app.js中,在client_server/lib/routing.js中定义为
Router.route('/', {
name:'start',
template:'start'
});
对应
<template name="start">
<input id="goToMobileBtn" type="button" value="Go to mobile view"/><br><br>
<input id="goToDesktopBtn" type="button" value="Go to desktop view"/>
</template>
提示:我发现因为“/”路由是第一个在[=47中定义的路由=],Router.go可选。
我有 4 个视图(模板):
- 开始
- showScannedData
- 仪表板
- 加载中
我在client_server/lib/routing.js中定义了路由:
Router.configure({
loadingTemplate: 'loading'
});
Router.route('/', {
name:'start',
template:'start'
});
Router.route('/mobile', {
name:'mobileStart',
template:'showScannedData'
});
Router.route('/desktop', {
name:'desktopStart',
template:'dashboard'
});
在client/app.js中我输入:
Router.go('/start');
有效。然而,模板 showScannedData 被渲染了两次,就好像我也将它设置为 templateLayout 一样。 至于我的应用程序 我不需要默认布局 但单个个人视图可以在开始时加载(模板:开始)或用户执行的特定操作(模板:showScannedData /仪表板)。
我做错了什么?
感谢@piscator 和@Keith 给我关键提示。
我发现,虽然我没有两次渲染模板,但我把
{{>> showScannedData}}
在project_name.html文件中(即不使用路由时渲染的文件)
所以我基本上从文件中删除了上面的行,并使用 Iron 的路由器通过以下方式转到入门模板:
Router.go("/")
在client/app.js中,在client_server/lib/routing.js中定义为
Router.route('/', {
name:'start',
template:'start'
});
对应
<template name="start">
<input id="goToMobileBtn" type="button" value="Go to mobile view"/><br><br>
<input id="goToDesktopBtn" type="button" value="Go to desktop view"/>
</template>
提示:我发现因为“/”路由是第一个在[=47中定义的路由=],Router.go可选。