{"title":"Redirection","description":"","section":"guides/controllers","version":"v1.5","path":"guides/controllers/redirection","canonical_url":"https://amberframework.org/docs/v1.5/guides/controllers/redirection","markdown_url":"https://amberframework.org/docs/v1.5/guides/controllers/redirection.md","inherited":true,"content_markdown":"# Redirection\n\nOften, we need to redirect to a new url in the middle of a request. A successful `create`action, for instance, will usually redirect to the `show` action for the model we just created. Alternately, it could redirect to the `index` action to show all the things of that same type. There are plenty of other cases where redirection is useful as well.\n\nCalling **redirect\\_to** will halt the request lifecycle.\n\n## Redirect to URL\n\n```crystal\nredirect_to(\n  location: \"\", \n  status: 302, \n  params: { \"key\" => \"value\" }, \n  flash: { \"user_id\" => \"1\" }\n)\n```\n\n## Redirect to Action\n\n```crystal\nredirect_to(\n  action: :index, \n  status: 302, \n  params: { \"key\" => \"value\" }, \n  flash: { \"user_id\" => \"1\" }\n)\n```\n\n## Redirect to Controller Action\n\n```crystal\nredirect_to(\n  controller: :symbol, \n  action: :index, \n  status: 302, \n  params: { \"key\" => \"value\" }, \n  flash: { \"user_id\" => \"1\" })\n```\n\n## Redirect Back\n\n```crystal\nredirect_back(\n  status: 302, \n  params: { \"key\" => \"value\" }, \n  flash: { \"user_id\" => \"1\" }\n)\n```"}