/** * Lightweight hash router for the app's tab views. * * Tabs are routable via the URL hash so a user can share/copy a URL for a * specific tab (e.g. #/radar) and use browser back/forward between tabs. * There is no nested route structure — just a single top-level view segment. */ export const VALID_VIEWS = ['current', 'hourly', 'daily', 'detail', 'radar'] export const DEFAULT_VIEW = 'current' /** * Parse a location hash into a view id, falling back to the default view. * Accepts '#/hourly', 'hourly', '#hourly', '', '#/unknown', etc. * * @param {string} [hash] - window.location.hash * @returns {string} one of VALID_VIEWS */ export function parseHash(hash = '') { const clean = String(hash).replace(/^#\/?/, '') const seg = clean.split('/')[0] return VALID_VIEWS.includes(seg) ? seg : DEFAULT_VIEW } /** * Convert a view id into its URL hash representation. * @param {string} view - one of VALID_VIEWS * @returns {string} e.g. '#/radar' */ export function viewToHash(view) { return `#/${view}` }