Skip to content

@unitools/router (alpha)

This is the official documentation of the @unitools/router package.

For Next.js

Installation

Terminal window
npm install @unitools/router @unitools/router-next

or

Terminal window
yarn add @unitools/router @unitools/router-next

Add module resolver to your next.config.js file.

next.config.js
module.exports = {
webpack(config) {
config.resolve.alias["@unitools/router"] = "@unitools/router-next";
return config;
},
};

For Expo

Installation

Install @unitools/router and @unitools/router-expo.

Terminal window
npm install @unitools/navigation @unitools/router-expo

or

Terminal window
yarn add @unitools/navigation @unitools/router-expo

Add module resolver to your babel.config.js file.

const path = require("path");
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: [
[
"module-resolver",
{
alias: {
"@unitools/router": "@unitools/router-expo",
},
},
],
],
};
};

Usage

import useRouter from "@unitools/router";
export default function Home() {
const router = useRouter();
return (
<View>
<Pressable
onPress={() => {
router.push("/about");
}}
>
<Text>About</Text>
</Pressable>
</View>
);
i;
}

Props

NameTypeDefaultDescription
push(path: string) => void-Pushes a new entry onto the history stack.
replace(path: string) => void-Replaces the current entry on the history stack.
back() => void-Equivalent to go(-1).
navigate(path: string) => void-Navigate to a specific URL.