浏览文章

文章信息

Magento2.3 登陆跳转模块编写login after redirect 17967


1、插件修改登陆行为

修改类LoginPost-> execute()上的after-plugin的解决方案。

2、解决:

/Vendor/Module/etc/frontend/di.xml

<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <type name="\Magento\Customer\Controller\Account\LoginPost">
    <plugin name="vendor_module_loginpostplugin" type="\Vendor\Module\Plugin\LoginPostPlugin" sortOrder="1" />
  </type>
</config>

/Vendor/Module/Plugin/LoginPostPlugin.php

<?php
/**
 * Created by PhpStorm.
 * User: 秋枫雁飞
 * Date: 2019/7/15
 * Time: 16:01
 */
 
namespace Vendor\Module\Plugin;
class LoginPostPlugin{
    /**
     * Change redirect after login to home instead of dashboard.
     *
     * @param \Magento\Customer\Controller\Account\LoginPost $subject
     * @param \Magento\Framework\Controller\Result\Redirect $result
     */
    public function afterExecute(
        \Magento\Customer\Controller\Account\LoginPost $subject,
        $result)
    {
        $result->setPath('/'); // Change this to what you want
        return $result;
    }
}


温馨提示:

$result->setPath('/');#这里跳转首页,你可以自行修改跳转其他路径,不需要写url,只写路径
$result->setUrl('https://demo.aiweline.com');#这里跳转跳转其他URL,这是另一个函数


原创