Like in BFS, knowing the distance is not enough. You need the path. Use a parent array. When you relax edge : if you update dist[v], also set parent[v] = u.
After Dijkstra finishes, reconstruct by walking backward: n → parent[n] → parent[parent[n]] → ... → 1. Reverse the list to get the path in order. If dist[target] is still infinity, no path exists. Initialize all parent values to so you can detect unreachable nodes during reconstruction.