簡體   English   中英

如何從`/`重定向到`/foo/<id> ` 使用 FlowRouter 和 MeteorJS?

[英]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.goFlowRouter.redirect重定向。

  1. 這可能嗎?
  2. 如果是,如何?

謝謝你的幫助!

由於路由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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM