[英]How to redirect from `/` to `/foo/<id>` using FlowRouter and MeteorJS?
在我的场景中,我希望访问我们的根 URL 的每个人都被自动重定向到包含用于协作和即时满足的文档的 URL。
这里, router.coffee 代码是:
FlowRouter.route '/',
action: ->
console.log "I'm home!"
FlowRouter.go 'myProject'
name: 'myHome'
FlowRouter.route '/my/:projectId',
subscriptions: (params) ->
@register 'currentProject', Meteor.subscribe 'project', params.projectId
action: ->
BlazeLayout.render 'myBody'
name: 'myProject'
我希望根 URL 重定向到/my/:projectId
但我不确定如何检索自动生成的projectId
并使用FlowRouter.go
或FlowRouter.redirect
重定向。
谢谢你的帮助!
由于路由action
执行时数据可能不可用,
最好是在模板级别重新路由。
使用Template.[name].onCreated()
函数可能是个好主意
并在其中放入类似以下代码的内容:
pID = ... // Get the user project ID from wherever you saved it
var params = {projectId: pID};
// Set the project URL including the :projectId parameter and re-route the user
FlowRouter.go("myProject", params);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.