normalize url and pathname and provide a onstate handler option