We consider decentralized detection for resource-constrained wireless sensor networks where local sensor decisions need to go through a multi-hop relay network before reaching the fusion center. Our objective is to collectively design sensor decision rules and relay rules for optimum detection performance. Under the Bayesian criterion, we establish the necessary conditions for an optimal system and derive the form of the optimal fusion rule at the fusion center. Under some conditional independence assumptions, we derive the forms of the optimal local decision rules and the optimal relay rules and show that the optimal set of decision rules for the entire system can be specified by a set of parameters. We demonstrate the advantages of our proposed systematic approach against more conventional design approaches through a numerical example.