text 路由目的地重定向

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 路由目的地重定向相关的知识,希望对你有一定的参考价值。

my_module.my_entity.add:
  route_name: node.add
  title: 'Add My Entity'
  route_parameters:
        node_type: 'my_entity'
  options:
    query:
      destination: '/path/to/redirect'
  appears_on:
    - my_module.my_entity.admin_content
    
    
    
\Drupal::destination()->get()    
\Drupal::request()->query->remove('destination')




With a route name on a Controller:

use Drupal\Core\Controller\ControllerBase;

class MyControllerClass extends ControllerBase {

  public function foo() {
    //...
    return $this->redirect('user.page');
  }
}
With a absolute url:

return new RedirectResponse('https://google.com');
On a form RedirectResponse doesn't work, then:

With a route name:

public function submitForm(array &$form, FormStateInterface $form_state) {
  //...

  $form_state->setRedirect('user.page');
}
With a absolute url:

public function submitForm(array &$form, FormStateInterface $form_state) {
  //...

  $form_state->setResponse(new TrustedRedirectResponse('https://google.com', 302));
  // You can change the response code from 302 to whatever you need
}



以上是关于text 路由目的地重定向的主要内容,如果未能解决你的问题,请参考以下文章

ICMP重定向

text 身份验证API路由重定向到登录页面

优维低代码:Redirect 路由重定向&If 条件渲染

39.伪造重定向ICMP数据包

39.伪造重定向ICMP数据包

react嵌套路由(多重路由)重定向,重定向到404页面,路由重定向