Britain has agreed to hand over the Chagos Islands to Mauritius to secure the future of a secretive military base in the Pacific Ocean.