title: FastAPI redirect gives method not allowed error
body: <p>I have created a route for login, where I post my form data and set a cookie. After setting the cookie I redirect to &quot;/main&quot; where I get <code>{detail:&quot;Method Not Allowed&quot;}</code> as a response.</p>
  <pre><code>@app.post(&quot;/login&quot;)
  async def login(request:Request):
       response = RedirectResponse(url=&quot;/main&quot;)
       response.set_cookie(key=&quot;cookie&quot;,value=&quot;key-value&quot;)
       return response
  
  @app.get(&quot;/main&quot;)
  async def root(request:Request, cookie: Optional[str] = Cookie(None)):
       if cookie:
          answer = &quot;set to %s&quot; % cookie
       else:
            answer = &quot;not set&quot;
  
       return {&quot;value&quot;: answer}
  </code></pre>
  <p>I furthered checked the console to find that a POST request is made to &quot;/main&quot; during the redirect and hence causing the error. When I change it to <code>app.post(&quot;/main&quot;)</code> it works fine. How do I avoid this error? I don't want to make post request to access &quot;/main&quot; everytime. Thanks in advance.</p>