useLocationByHostContext
useLocationByHostContext resolves the current Business based on the configured host (domain) and exposes a business-scoped httpClient, a root apiClient, and the business record. It bootstraps the location context used across the app and is intended to wrap the whole application.
Typical flow: the app loads using the current host (e.g. acme.spaces.Néxudus.com), LocationByHostProvider finds the matching Business, and makes that available to all children. Route-level overrides can later switch business via useLocationByRouteContext.
What you get
Id: number– Current business IDWebAddress: string– Current business web addresshttpClient: HttpClient– Axios-like client scoped tohttps://{WebAddress}.spaces.Néxudus.comapiClient: HttpClient– API root client usingapiBaseUrlfrom app configbusiness: Business– Business details fromendpoints.system.business
Provider and placement
You must render the provider at the app root, before anything that consumes location state. The repository already does this insrc/App.tsx:
useLocationByHostContext or useLocationByRouteContext is safely wrapped.
How it works
- Reads
config.hostfromuseAppConfig(). - Fetches
GET /api/sys/businesses/getByHost?host={config.host}using the rootapiClient(config.apiBaseUrl). - Builds
httpClient = ApiHttpClient(WebAddress)andapiClient = ApiHttpClient(config.apiBaseUrl). - Fetches
businessviaendpoints.system.businesswithincludeHeaders: falseto avoid cache invalidation on auth changes. - Throws
NO_BUSINESS_FOR_HOSTif no matching business is found.
src/states/useLocationDomainContext.tsx.
Usage example
useLocationByRouteContext will override the httpClient and business when a :webAddress is present in the route; otherwise, consumers see this host-level context.
Edge cases and errors
- Usage outside the provider throws:
useLocationByHostContext must be used within an LocationByHostContext. - Suspense: data loading is Suspense-based, so ensure a
<Suspense>boundary above the provider tree (the app already has one inLocationContext). NO_BUSINESS_FOR_HOSTindicates misconfiguration of the domain/host.
See also
- useLocationByRouteContext – Route param override for business context
- LocationContext – Provider composition used by the app