These functions trigger state updates in the browser's history session, allowing you to transition between pages programmatically.


goToPage

Adds a new entry to the browser's history stack.

typescript
1function goToPage(2    pathname: string,3    pageData: Record<string, unknown> = {},4    title: string = document.title5): Promise<void>

Example

javascript
1import { goToPage } from '@beforesemicolon/router'2 3await goToPage(4    '/users/42',5    { role: 'admin', scrollPosition: 0 },6    'User Profile'7)

replacePage

Updates the current entry in the history stack instead of creating a new one. This is ideal for redirections so clicking the browser's back button doesn't trap the user in a redirect loop.

typescript
1function replacePage(2    pathname: string,3    pageData: Record<string, unknown> = {},4    title: string = document.title5): Promise<void>

Example

javascript
1import { replacePage } from '@beforesemicolon/router'2 3if (!isAuthenticated) {4    await replacePage('/login', { from: '/dashboard' }, 'Please Login')5}

previousPage

Navigates back to the previous entry in the browser session. Identical to clicking the browser's back button.

typescript
1function previousPage(): void

nextPage

Navigates forward to the next entry in the browser session. Identical to clicking the browser's forward button.

typescript
1function nextPage(): void
edit this doc