Usually you start with an infinite total cost for all nodes that have not yet been explored. Then you can tweak the algorithm a bit to save the predecessor:
for each of node neighbours n if n is not in explored if n is not in frontier frontier.add(n) set n predecessor to node elif n is in frontier with higher cost replace existing node with n set n predecessor to node
After that, you can simply check the sequence of predecessors, starting with your goal.
source share