Strapi Version : 3.3.4
Facing this issue where on clicking Save/publish , user is not redirected to listing page as was the case with 3.0.2 version. This is causing confusion. Kindly help to resolve.
On clicking Save/ Publish button , how to redirect user to Listing Page ?
To make it work you will need to override the content-manager plugin and add a goback action after the entry being published.
Steps to do it.
1. Override the EditView Page/Container
First copy the component from:
./cache/plugins/strapi-plugin-content-manager/admin/src/containers/EditView/index.js
This file is your React component for the form pages of collections.
Create the override version of the file on the following path:
extensions/content-manager/admin/src/containers/EditView/index.js
We will just add a new props to the component Header
inside this component.
Find for Header
at the file and change to become like this:
Current state of the component
<Header allowedActions={allowedActions} />
Change to this:
<Header allowedActions={allowedActions} goBack={goBack} />
This step is ok, now we need to change the Header
component to use the goBack()
when the entry is published.
2. Override the Header component
Copy the component from:
./cache/plugins/strapi-plugin-content-manager/admin/src/containers/EditView/Header/index.js
Create the override version of the file on the following path:
extensions/content-manager/admin/src/containers/EditView/Header/index.js
At this file, you will first need to add the goBack to the component props
const Header = ({
... // PREVIOUS PROPS
goBack
}) => {
...
Now you need to find the onClick
method, is probably something like this
const onClick = isPublished
? () => setWarningUnpublish(true)
: e => {
if (!checkIfHasDraftRelations()) {
onPublish(e);
} else {
setShowWarningDraftRelation(true);
}
};
At this point you need to add the goBack right after the onPublish(e) call.
This is how it will going to look like.
const onClick = isPublished
? () => setWarningUnpublish(true)
: e => {
if (!checkIfHasDraftRelations()) {
onPublish(e);
goBack()
} else {
setShowWarningDraftRelation(true);
}
};
I hope it helps someone