简体   繁体   English

从根链接到重定向的路由

[英]Link to redirected route from root

For my application, the objective is that the user goes goes to the root and it automatically redirects to a route based on the day of the week. 对于我的应用程序,目标是使用户转到根目录,并根据星期几自动重定向到路由。 It currently works, as long as the user goes to the route by inputing the URI. 只要用户通过输入URI转到路线,它就可以正常工作。 However, I am unsure how to link to this, as when I try to do href="/" , it just goes to the root of the application, not the intended redirect route. 但是,我不确定如何链接到该链接,因为当我尝试执行href="/" ,它只是转到应用程序的根目录,而不是预期的重定向路由。 Not sure if I'm just thinking about this in the wrong way. 不知道我是否以错误的方式考虑了这个问题。 Below is my current code for the routes. 以下是我目前的路线代码。

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');
    }
  },
});

Then I simply link to the root by using <a href="/">Home</a> , and of course, this doesn't work. 然后,我只是使用<a href="/">Home</a>链接到根,当然,这是行不通的。

I believe you want to use redirect instead of go since you are already in a route, ex: 我相信您想使用redirect而不是go因为您已经在路由中,例如:

redirect('/boards/sunday')

instead of 代替

FlowRouter.go('/boards/sunday')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM