Project: bookmarks.dev - File: public-routing.module.ts

The ** wildcard has to be defined as a child of the root you want redirected back to. Thus URLs like https://www.bookmarks.dev/snippets/60046e4554aac471e0799da7/some-mongo-title-here will still “point” to https://www.bookmarks.dev/snippets/60046e4554aac471e0799da7:

  {
    path: 'snippets/:id',
    component: PublicSnippetDetailsComponent,
    children: [
      // This is a WILDCARD CATCH-ALL route that is scoped to the "/snippets/:snippetid"
      // route prefix. It will only catch non-matching routes that live
      // within this portion of the router tree.
      {
        path: '**',
        component: PublicSnippetDetailsComponent
      }
    ]
  },

Reference - https://angular.io/guide/router#setting-up-redirects


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

You might need to update a dependency only in your package-lock.json file, because there might be a security vulnerability for the version you use but you can’t update the dependency in your package.json that uses that dependency. You can use --no-save and --package-lock-only options as in the example below

npm install y18n@4.0.1 --no-save --package-lock-only

Reference - https://docs.npmjs.com/cli/v6/configuring-npm/package-locks


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Just use the simple quotes ' and + sign inside the double quotes of the html attribute value. See the value of the href attribute below:

<div class="float-right mt-1">
  <a
    *ngIf="snippet.public"
    type="button" class="btn btn-light btn-sm float-right"
    href="mailto:?subject=Code snippet: &body=https://www.bookmarks.dev/snippets/"
    title="Share link to snippet via Email">
    <i class="far fa-envelope"></i> Email
  </a>
</div>

Reference - https://github.com/BookmarksDev/bookmarks.dev


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use the export keyword:

import { SearchDomain } from './search-domain.enum';

export const searchDomains: any = new Map([
  [SearchDomain.MY_BOOKMARKS, 'My Bookmarks'],
  [SearchDomain.PUBLIC_BOOKMARKS, 'Public Bookmarks'],
  [SearchDomain.MY_SNIPPETS, 'My Snippets'],
  [SearchDomain.PUBLIC_SNIPPETS, 'Public Snippets']
]);

In the consumer file we import it:

import { searchDomains } from '../../core/model/search-domains-map';

export class SearchbarComponent implements OnInit {
    searchDomains = searchDomains;
    //...
}

Reference - https://www.typescriptlang.org/docs/handbook/modules.html


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use the regular Map constructor to transform a 2D key-value Array into a map

const searchDomains: any = new Map([
  [SearchDomain.MY_BOOKMARKS, 'My Bookmarks'],
  [SearchDomain.PUBLIC_BOOKMARKS, 'Public Bookmarks'],
  [SearchDomain.MY_SNIPPETS, 'My Snippets'],
  [SearchDomain.PUBLIC_SNIPPETS, 'Public Snippets']
]);

searchDomains.get(SearchDomain.MY_BOOKMARKS) // returns "My Bookmarks"

Use Array.from() to transform a map into a 2D key-value Array

console.log(Array.from(searchDomains)) // Will show you exactly the same Array as kvArray

Reference - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map


Shared with from Bookmarks.dev. Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.