So again we can delete a post but when it gets deleted we should really navigate the user automatically 2
back to the index. 3
We've really already done this before almost this exact same action inside of the post component. 4
So remember when we created our form we grab the contacts we got our router and then when a user successfully 5
created the post we navigated navigated them back to the index route right here. 6
I encourage you to pause a video at this point and go ahead and try to implement this feature by yourself 7
. 8
It's going to look very similar to what we already did right here. 9
So if you want to give it a shot yourself feel free to pause right now. 10
Otherwise we're just going to dive right into it. 11
OK. 12
So step one at the top. 13
We're going to import the product types again to make use inside of our context types assignment. 14
So we'll say static contex types that's going to be an object and we specifically want access to the 15
router piece of context which is the product types dot object. 16
Remember that comes from the re-act import up here. 17
So this gives us access to the router. 18
Now we want to make sure that we navigate back to the index only after the post is successfully deleted 19
because our action creator contains a promise on the payload property or action created right here. 20
We return a promise as well. 21
And so we can chain on with a dot then. 22
And inside there we'll just define our function and very straight forward. 23
We'll say this Tom context router pushed back to the index. 24
That's it. 25
Nice and simple. 26
I'm going to save this. 27
And let's go ahead and give it a shot. 28
Refresh the page delete the posts and we get navigated automatically back to our post index page. 29
I've got a duplicate blog post in here right here so let's go ahead and clean this one up. 30
So we'll delete it and it gets cleaned up. 31
Nice. 32
OK. 33
This is looking pretty darned good. 34
Let's go ahead and wrap up in the next section