[英]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.