River networks are important hydrologic features in Earth system models (ESMs) and hydrological models at both regional and global scales. The performance of streamflow and inundation simulation rely on the quality of river network, including its flow direction, channel geometry and slope. However, the representation of river network is often constrained by the spatial resolution and spatial discretization, and river network topology information is often underrepresented or overly simplified. In this study, we developed a topology based river network generation method for spatially-distributed hydrological models. This method (1) uses vector river flowline to preserve network topology through graph theory; (2) uses spatial discretization and river network intersection to reconstruct grid topology. The advantages of our method include that (1) it combines the advantages of rasterization and vector topology under the same framework; (2) it is mesh independent and can be applied to both structured and unstructured meshes. This method paves a path for advanced stream burning and depression filling algorithms to model flow direction and river channel geometry across different scales. This work is a next-generation development for the Energy Exascale Earth System Model (E3SM), designed to enable coupled hydrological modeling for unstructured mesh ESMs.