@wordpress/route 是 WordPress 管理界面的路由工具包,提供 TanStack Router 的共享实例,确保路由一致性。它包含公共 API 如钩子和组件,以及用于路由器设置的私有 API。
import { Link, useNavigate, useParams, useRouter, useSearch } from '@wordpress/route';
function MyRoute() {
const params = useParams();
const navigate = useNavigate();
const search = useSearch();
return (
<div>
<Link to="/other-route">Go to other route</Link>
<button onClick={() => navigate({ to: '/somewhere' })}>
Navigate
</button>
</div>
);
}Routing utilities for WordPress admin interfaces, providing a shared instance of TanStack Router.
Install the module:
npm install @wordpress/route --save
This package provides a shared instance of TanStack Router to ensure consistent routing across WordPress admin interfaces.
The following hooks and components are available for use in routes:
import { Link, useNavigate, useParams, useRouter, useSearch } from '@wordpress/route';
function MyRoute() {
const params = useParams();
const navigate = useNavigate();
const search = useSearch();
return (
<div>
<Link to="/other-route">Go to other route</Link>
<button onClick={() => navigate({ to: '/somewhere' })}>
Navigate
</button>
</div>
);
}
The boot package uses private APIs for router setup. These should not be used by individual routes.
This is an individual package that’s part of the Gutenberg project. The project is organized as a monorepo. It’s made up of multiple self-contained software packages, each with a specific purpose.
To find out more about contributing to this package or Gutenberg as a whole, please read the project’s main contributor guide.