z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.13k stars 2.81k forks source link

Pjax导致新页面丢失css和inline脚本的问题修复 #3166

Closed robinhoo1973 closed 5 years ago

robinhoo1973 commented 5 years ago

Description:

当调用新页面而且有自定义的Admin::css或Admin::script的时候会出现丢失现象。而且这个问题在框架里也有表现,那就是很多当前页面没有用的script和css都在页面中被调用,可能也是为了别面出现css或脚本不起作用的情况。

Steps To Avoid:

避免的方法, 1.在你的index方法里加上

if(request()->url()!=url()->previouse()){
     Admin::disablePjax();
}

2.修改vendor/encore/laravel-admin/src/Middleware/Pjax.php第34行的那段try block为下面的代码

        if($request->url()==url()->previous()){
            try {
                $this->filterResponse($response, $request->header('X-PJAX-CONTAINER'))
                    ->setUriHeader($response, $request);
            } catch (\Exception $exception) {
            }
        }
nkjackzhang commented 5 years ago

这个方法相当于大部分情况都禁用了pjax,属于不是办法的办法了,另外我是在bootstrap.php里加上的判断,index里这些helper都不太好用,而且方法名是previous()。不过最终我选择的是Admin::css和Admin::js里的内容放到bootstrap.php里了,Admin::script里的东西还是放到原来位置,因为它在模板的位置是在#pjax-container里的。

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.