Wouter Versions Save

πŸ₯’ A minimalist-friendly ~2.1KB routing for React and Preact

v2.8.1

1 year ago
  • When route parameters can be inferred from the path, they now have a type of { readonly [k in string]: string | undefined }. This takes into account optional segments that can be undefined #262, thanks @HansBrende
  • Proper typings of Route children: it does not allow mixing render props and other elements together #263, thanks @HansBrende
  • Switch now has less strict type of its children to allow conditional rendering and avoid confusion https://github.com/molefrog/wouter/commit/8f943abc72abb89f35b3cd6d2a57781106cef1b5

v2.8.0

1 year ago
  • Feature: Route parameters are now automatically inferred in TypeScript. @itsMapleLeaf via #211
  • Feature: Link component will now forward ref to the underlying a element of custom component provided by user. @trymoto via #259
  • Optimization: use useState instead of useRef for values that must be initialized only once. @HelKyle via #252 and #251
  • Bugfix: Prevent Link navigation when event was cancelled. @Tomas2D via #239

πŸ‡ΊπŸ‡¦ We stand with Ukraine Donate or spread the world to help Ukrainian soldiers and refugees

v2.7.5

2 years ago

v2.7.4

3 years ago
  • Fix incorrect type of the makeMatcher function, @shannonrothe via #182
  • Fix a bug with useLocation not triggering the update with query string is changed, @wuzzeb via #178

v2.7.3

3 years ago
  • Fixed a regression bug introduced in v2.7.2: a path returned from useLocation() included a query string value e.g. "/foo?bar=baz", while it should have been just "/foo". See #170 for details.

v2.7.0

3 years ago

We're continuing to improve the library by keeping it small and simple, thanks to our wonderful contributors. First of all, it's the React 17 support: I'm sure many of you have already upgraded your project to the new version of React, which apparently "has no new features". Wouter now has proper peerDependencies that allow you to use it with React 17 thanks to @omgovich!

Another important update is that it's now possible to access the routes outside of the base scope when using a base parameter:

<Router base="/app">
  <Link href="/relative">Relative Link</Link>
  {/* 
      by prexing a path with tilda, you can reference a global route: when you click on this link 
      it navigates you to "/absolute", and not "/app/absolute" 
   */}
  <Link href="~/absolute">Absolute Link</Link>
</Router>

See https://github.com/molefrog/wouter/pull/153 for more info. Credits @jvdsande

v2.5.2

3 years ago

This patch release contains a few important bug-fixes:

  • base parameter in Router is now case-insensitive. Thanks @Veranete @cbbfcd via #138
  • Fixed a "func.apply is not a function" error when using a custom matcher. @cbbfcd via #137
  • The list of events is now exported from the use-location.js module. @o-alexandrov via #129

Happy wouting!

v2.5.1

3 years ago

This release aims to fix a problem when a subpath module require("wouter/static-location") can't be properly required from Node.js, thanks @davidje13 #126

Wouter now properly supports ESM and CommonJS environments and it can even work within .mjs scripts!

v2.5.0

3 years ago

✨ The new release brings up several important updates!

  • The new project logo, thanks to Katya Simacheva

  • Released in 2.5.1 Wouter now targets ESM Node modules and properly supports CJS submodules. #126 thanks @davidje13

  • Using a default route in a Switch just became easier: use <Route /> component with no props and it will match everything that didn't match regular routes. @cbbfcd via #103

<Switch>
  <Route path="/users> ... </Route>
- <Route path="/:rest*">
+ <Route>
    Not Found!
  </Route>
</Switch>

check out the Demo β†’

  • Static location hook now supports record: option, which allows to save the history of location changes in hook.history. It improves the testing DX and allows to detect redirects in SSR responses. #113, thanks @davidje13
  • Link and Redirect components now can accept replace option that will tell wouter that replaceState navigation should be used. Example:
<Link to="/users" replace>Users</Link>
<Redirect to="/home" replace />
  • Some tiny updates in the README: table of contents for better navigation, more examples, testimonials! It's such an honor to see that wouter's community is getting bigger and developers trust it in production: image

  • The entire type definition codebase had been reworked! Types are updated to support latest features like default routes and replace navigation, and to support custom location hooks that might have specific navigational options. This change is especially important in terms of wouter's new strategy: supporting new features through external extendability see https://github.com/molefrog/wouter/issues/102#issuecomment-654694679.

This will allow us to easily implement custom location hooks, that can for example support state changes:

import { useLocation } from "wouter";
import useLocationWithState, { LocationWithState }  from '@wouter/use-location-state';

const NavigateWithState = () => {
  // useLocation is a generic function that can accept the custom location hook type
  const [location, update] = useLocation<LocationWithState>();
  
  const onClick = useCallback(() => {
    // this is now a valid function call, `state:` option is included in LocationWithState type
    update("/home", state: { foo: "bar" });
  }, [update]);

  return null;
}

const App = () => (
  <Router hook={useLocationWithState}>
    <Link<LocationWithState> to="/app" state={{ foo: 'bar' }}>Click Me!</Link>
  </Router>
);

v2.4.0

4 years ago

Though the base path support was possible before, via a custom useLocation hook, it wasn't fully SEO-friendly β€” for example, the link would still have a relative href attribute.

After a long discussion, it's been decided to enable the base path support on a top-level Router component πŸŽ‰ You can now just wrap your app with <Router base="/app"> and that's it! Learn more about this feature β†’

The added bundle cost is just 48 extra bytes.

@omgovich @cbbfcd @guiem via #76