Skip to content

Instantly share code, notes, and snippets.

@jasonaden
jasonaden / api.ts
Last active September 20, 2018 18:06
Update Params without Navigation API
// Existing API
export interface NavigationExtras {
relativeTo?: ActivatedRoute|null;
queryParams?: Params|null;
fragment?: string;
preserveQueryParams?: boolean;
queryParamsHandling?: QueryParamsHandling|null;
preserveFragment?: boolean;
skipLocationChange?: boolean;
@jasonaden
jasonaden / guard_redirect.ts
Last active October 31, 2018 22:48
Using Guards Redirect
/*
* Guards execute in a similar way to how they used to. However, there is now prioritization involved. A guard
* closest to the root of the application takes priority, such that if guards for child routes return `false`
* or a `UrlTree` but parents haven't resolved yet, we will wait for the parents to resolve first. The highest
* prioirty failure (either `false` or `UrlTree` redirect) will take priority.
*
* If a `UrlTree` is returned from a guard, the current navigation will be cancelled (firing a `NavigationCancel`
* event) and a new navigation will be kicked off to the redirected URL.
*/
@jasonaden
jasonaden / nav_no_events.ts
Created November 1, 2018 05:47
Navigate without navigation events
/*
* The first piece is to add an option to RunGuardsAndResolvers that ignores optional params.
* With this option enabled, we would only run guards and resolvers for required params,
* ignoring optionals (matrix and query params).
*/
export type RunGuardsAndResolvers = 'paramsChange' | 'paramsOrQueryParamsChange' | 'always' |
'pathParamsChange'; // last option is new
// With the above option, we should see these tests pass:
  • When restoring state, restore the full state rather than just the navigationId.
    • Can this cause a problem?
    • Talk to Igor about this possibly breaking change. Might need to only restore state when there is a navigationId present so the types don't cause a breakage.
    • feat(router): restore whole state object when navigating back to a page managed by Angular router
  • Allow passing of state to navigate and navigateByUrl.
  • Merge this state with navigationId when applicable. Find where we are setting navigationId as I think it is there on every navigation as currently implemented.
    • feat(router): allow passing state to navigate and navigateById methods
  • Allow state to be set for routerLink directives
    • feat(router): allow passing state to routerLink directives
  • Wire in state to all events.
@jasonaden
jasonaden / stats.json
Last active June 15, 2023 00:30
Stats file from rollup-plugin-visualizer for debugging
{
"version": 2,
"tree": {
"name": "root",
"children": [
{
"name": "assets/index-625bb411.js",
"children": [
{
"name": "src",
@jasonaden
jasonaden / Upgrade.md
Last active August 2, 2023 19:02
Upgrade React Router to v6

Upgrade React Router to v6

React Router recently made a major shift with the v6 router. There are some key improvements we want to take advantage of. Some of these include:

  • More intelligent routing, not relying on the exact prop or the order of the route definitions.
  • Relative routes and linking. No more parent route paths for nested routes.
  • New Outlet component, allowing us to decide where to render child routes.
  • Smaller bundle sizes
  • Suspense-aware navigation using the new navigate function (rather than using history API in v5)
  • In the most current versions of React Router, a new set of data-enabled APIs have been added, giving us access to functionality like pre-route loading, route-level form handling, and better route error handling.
@jasonaden
jasonaden / external-log.js
Created October 3, 2024 18:28
Set up external logging so we can log after `visibilitychange` event
// Open a new window
var logWindow = window.open("", "LogWindow", "width=600,height=400");
// Write initial HTML content to the new window
logWindow.document.write(`
<html>
<head>
<title>External Log Window</title>
<style>
body { font-family: monospace; background-color: #f0f0f0; padding: 10px; }