How to programmatically navigate using preact-router?

I am trying to understand how to structure the front-end of a web application using typescript, preact and preact-router. I have come a long way, but I still need to figure out how to programmatically navigate (redirect) using preact-router. I can do it history.replaceState(null, null, '/#/redirectedUrl');, but while this changes the URL in the address bar, preact-router does not route the new URL.

What is the preferred way to programmatically navigate using preact-router?

+7
source share
2 answers

Importing a function routefrom 'preact-router'is a way:

import { route } from 'preact-router';
route('/url/to/rout/to');
+8
source

import { route } from 'preact-router';
route('url');

pushState ( ), URL

import { route } from 'preact-router';
route('url', true);

replaceState ( ), URL URL, . , , home/dashbaord, , ( dashbaord).

0

Source: https://habr.com/ru/post/1671932/


All Articles