For the complete documentation index, see llms.txt. This page is also available as Markdown.

React Router

The example setup is live here: https://example-react-router.oidc-spa.dev/

Run it locally with:

npx degit https://github.com/keycloakify/oidc-spa/examples/react-router oidc-spa-react-router
cd oidc-spa-react-router
cp .env.local.sample .env.local
yarn
yarn dev

This is for setting for integrating oidc-spa with react-router in Framework Mode.

Enabling SPA mode

As of today, to use oidc-spa you need to enable SPA mode.

oidc.client.ts

Make sure you create a app/oidc.client.ts file, (instead of app/oidc.ts).

Example of oidc.client.ts file

Setting up the entrypoint

Create thoses two files:

app/entry.client.tsx
app/entry.client.lazy.tsx

Working with loaders

The default approach when you want to enforce that the user be logged in when accesing a given route is to wrap the component into withLoginEnforced(), example:

This approach is framework agnostic and always works however, you might want to use the loaders to doload the data, for that you would use enforceLogin() istead of withLoginEnforced:

Running the example

The example setup is live here: https://example-react-router-framework.oidc-spa.dev/

Run it locally with:

Last updated

Was this helpful?