2016-05-02 52 views
0

對於我的應用程序,其目標是用戶轉到根目錄並自動重定向到基於星期幾的路線。它目前工作,只要用戶通過輸入URI來轉到路由。但是,我不確定如何鏈接到此,因爲當我嘗試執行href="/"時,它只是轉到應用程序的根目錄,而不是預期的重定向路線。不知道我是否以錯誤的方式思考這個問題。以下是我目前的路線代碼。鏈接到從根目錄重定向的路線

FlowRouter.route('/boards/:slug', { 
    name: 'Boards.show', 
    action() { 
    mount(AppContainer, { 
     main: <BoardContainer/>, 
    }); 
    }, 
}); 

FlowRouter.route('/', { 
    name: 'Home', 
    action() { 
    let day = new Date().getDay(); 

    if (day === 0) { 
     FlowRouter.go('/boards/sunday'); 
    } else if (day === 1) { 
     FlowRouter.go('/boards/monday'); 
    } else if (day === 2) { 
     FlowRouter.go('/boards/tuesday'); 
    } else if (day === 3) { 
     FlowRouter.go('/boards/wednesday'); 
    } else if (day === 4) { 
     FlowRouter.go('/boards/thursday'); 
    } else if (day === 5) { 
     FlowRouter.go('/boards/friday'); 
    } else if (day === 6) { 
     FlowRouter.go('/boards/saturday'); 
    } 
    }, 
}); 

然後,我簡單地使用<a href="/">Home</a>鏈接到根,當然,這是行不通的。

回答

0

我相信你想使用redirect而不是go,因爲你已經在一個路由,例如:

redirect('/boards/sunday') 

,而不是

FlowRouter.go('/boards/sunday')