关于将用户重定向到受保护内容的帮助

继续讨论 Gated Topics in Category

我试图修改 gated 组件,将其重定向到特定页面,而不是显示一个 gate

1
我在主题创建者中尝试了 DiscourseURL.routeTo('/t/table-builder-test-2/1667'),它有效,但加载需要一段时间并会引发错误,尽管页面已成功加载。

2
我还尝试了 setDefaultHomepage('/t/table-builder-test-2/1667');

      const container = Discourse.__container__;
      const router = container.lookup("router:main");

      let topicId = router.currentRoute.parent.params.id

      PreloadStore.remove(`topic/${topicId}`);

它只会在加载 gated 页面后重定向,然后单击返回按钮。

3
location.href = '/t/table-builder-test-2/1667'

它有效,但 gated 页面也会加载几秒钟,不像 1 那样流畅。

实现此目的的最佳方法是什么?

我的 自定义主页 主题会更改主页。诀窍在于,有些内容会被预加载,您必须执行一些操作才能将其移除。

希望您能在代码中找到示例,因为这是我能用手机解释清楚的最好方式。 :person_shrugging:

1 个赞

我尝试了以下代码:

let topicId = router.currentRoute.parent.params.id
PreloadStore.remove(`topic/${topicId}`);

但它不起作用,我们是否有关于 PreloadStore.remove 方法如何工作的文档?