Wireless mesh networks (WMNs) have attracted increasing attention and deployment as a high-performance and low-cost solution to last-mile broadband internet access. WMNs have been broadly accepted in the conventional application sectors of ad hoc networks because of their advantages over other wireless networks. Traffic routing has a critical role in determining the performance of wireless mesh networks. Routing protocol design for wireless mesh networks is critical to maintain the performance and reliability of wireless mesh networks. Thus a routing protocol or an algorithm for WMNs should be carefully designed taking into account the specific characteristics of that network. Traditional routing protocols send traffic along pre-determined paths and have been shown ineffective in coping with unreliable and unpredictable wireless medium. In this paper we propose to formulate the mesh network routing problem as an optimisation problem. In the formulation of the problem we have considered both the static and dynamic traffic demand. This paper proposes a dynamic routing algorithm that is able to provide the optimal performance on all possible traffic demands. Our simulation results show that the proposed method performs competitively.