[英]How to redirect from `/` to `/foo/<id>` using FlowRouter and MeteorJS?
In my scenario, I want everyone that visits our root URL to be auto-redirected to a url containing a document for collaboration and instant gratification.在我的场景中,我希望访问我们的根 URL 的每个人都被自动重定向到包含用于协作和即时满足的文档的 URL。
Here, the router.coffee code is:这里, 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'
I want the root URL to redirect to /my/:projectId
but I'm unsure of how to retrieve the auto-generated projectId
and redirect using with either FlowRouter.go
or FlowRouter.redirect
.我希望根 URL 重定向到/my/:projectId
但我不确定如何检索自动生成的projectId
并使用FlowRouter.go
或FlowRouter.redirect
重定向。
Thanks for your help!谢谢你的帮助!
Since the data may not be available when the route action
execute,由于路由action
执行时数据可能不可用,
the best is to re-route at the template level .最好是在模板级别重新路由。
It might be a good idea to use the Template.[name].onCreated()
function使用Template.[name].onCreated()
函数可能是个好主意
and put inside it something like the following code:并在其中放入类似以下代码的内容:
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.