方式一:官网提供了nginx的配置,这样弊端前端所有接口都会重定向到index.html文件
nginx
location / {
try_files $uri $uri/ /index.html;
}
方式二:实现思路,重定向控制器到前端资源所包含的index.html文件
例:后端php前端对应AccountInfo路由,在服务端需要对应建立AccountInfoController控制器,控制器重定向到index界面,index界面我这指向文件路径main.php(frontend/views/layouts/main.php) ,粘贴前端打包生成的dist/index.html所有代码到main.php文件。
use yii\web\Controller;
class AccountInfoController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
}