Help on redirect user on gated content

AI-generated summary

The discussion revolves around redirecting users away from gated content pages to a specific topic instead of displaying the gate. th21 experimented with several methods: using DiscourseURL.routeTo() (which works but causes delays and errors), setDefaultHomepage() with PreloadStore.remove() (which only redirects after loading the gate and pressing back), and location.href (which works but briefly shows the gated page). pfaffman references their Custom Homepage theme as a potential solution, noting that preloading and clearing it is key. th21 asks for documentation on how PreloadStore.remove functions, as their attempt did not work.

Continuing the discussion from Gated Topics in Category:

I was trying to modify the gated component to redirect the user to a specific page instead of showing a gate

1
I tried DiscourseURL.routeTo('/t/table-builder-test-2/1667') on theme creator, it works but takes a while and throws errors on loading, although the page is successfully loaded.

2
I also tried with setDefaultHomepage('/t/table-builder-test-2/1667'); and

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

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

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

It only redirects after the gated page is loaded then click on the back button.

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

It works but the gated pages also loaded for a few secs, unlike 1 do it smoothly.

What is the best way to achieve this?

My Custom Homepage theme changes the home page. The trick is that some stuff gets preloaded and you have to do something to make it go away.

Hopefully you can find the example in the code, as that’s the best I can explain it from my phone. :person_shrugging:

I tried with

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

but it doesn’t work, do we have a document about how the PreloadStore.remove method works?