_spPageContextInfo.currentUICultureName not defined in Custom Routing

Hello community,

I've configured a simple custom routing based on the browser language:

if(_spPageContextInfo.currentUICultureName === 'en-US'){

return '2102fead-fdb1-41e7-b53d-6894a3a57547';

}
Unfortunately, the routing isn't working, and I'm getting the following error in the console:

ReferenceError: _spPageContextInfo is not defined

What could be causing this?

Thanks in advance!

OK. I found the solution: Using

if(navigator.language === 'en-US'){
return '2102fead-fdb1-41e7-b53d-6894a3a57547';
}

instead of

if(_spPageContextInfo.currentUICultureName === 'en-US'){

return '2102fead-fdb1-41e7-b53d-6894a3a57547';
}

solved my problem