Router

navigate

Programmatic navigation function for Manic router.

navigate()

The navigate function provides programmatic navigation between routes without user interaction.

Function Signature

import {  } from 'manicjs';

// Navigate to a path
('/about');

// Navigate with options
('/posts/123', { : true });

Parameters

Prop

Type

Prop

Type

Return Value

// Returns void - navigates synchronously
function navigate(to: string, options?: NavigateOptions): void;

Examples

Basic Navigation

import {  } from 'manicjs';

// User login handler
async function (: string, : string) {
  const  = await ('/api/login', {
    : 'POST',
    : .({ ,  }),
  });
  
  if (.) {
    ('/dashboard');
  }
}

Replace History

import {  } from 'manicjs';

// Redirect after action - don't let user go back
function () {
  ('/login', { : true });
}

Scroll Control

import {  } from 'manicjs';

// Use normal navigation; scroll behavior is controlled by the router config.
function (: string) {
  (`/?filter=${}`);
}

Type Definitions

interface NavigateOptions {
  replace?: boolean;
}

declare function navigate(to: string, options?: NavigateOptions): void;

See Also

On this page