Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Last active September 27, 2020 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NullVoxPopuli/c268d280e51a5dd64e780f860faa1330 to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/c268d280e51a5dd64e780f860faa1330 to your computer and use it in GitHub Desktop.
Custom Link Component
Routing Info:
<dl>
<dt>currentURL</dt>
<dd>{{this.router.currentURL}}</dd>
<dt>currentRoute</dt>
<dd>{{this.router.currentRouteName}}</dd>
</dl>
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
export default class extends Component {
@service router;
}
<nav class="grid gap-4">
<Link @href="https://emberjs.com" target="_blank">
External Page
</Link>
<Link @href="/">
Index
</Link>
<Link @href="/a">
route a
</Link>
<Link @href="/c">
route c
</Link>
<Link @href="/c/1">
with dynamic segment
</Link>
<Link @href="/c/1/foo">
two dynamic segments
</Link>
<Link @href="/c/1/foo?q=query&foo=bar&applicationQP=oof">
with query params
</Link>
</nav>
import Controller from '@ember/controller';
export default class CSubC extends Controller {
queryParams = ['applicationQP'];
}
import Controller from '@ember/controller';
export default class CSubSubC extends Controller {
queryParams = ['foo'];
}
import Controller from '@ember/controller';
export default class CSubC extends Controller {
queryParams = ['q'];
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
export default class Router extends EmberRouter {
location = 'none';
// rootURL is typically set to config.rootURL
// but in ember-twiddle, config.rootURL is `undefined`
rootURL = '/';
}
Router.map(function() {
this.route('a');
this.route('b');
this.route('c', function() {
this.route('sub-c', { path: ':id' }, function () {
this.route('sub-sub-c', { path: ':dynamic-param' });
});
});
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
/* Tailwind Lite*/
.grid {
display: grid;
}
.gap-4 {
grid-gap: 1rem;
}
.grid-flow-col {
grid-auto-flow: column;
}
.text-color-red {
color: red;
}
<h1>How to make your own Link Component</h1>
<Nav />
<hr>
{{outlet}}
<Info />
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { start } from 'ember-qunit';
import { resetOnerror } from '@ember/test-helpers';
import QUnit from 'qunit';
QUnit.testDone(function() {
resetOnerror();
})
let attributes = {
rootElement: '#ember-testing',
autoboot: false
};
attributes = assign(attributes, config.APP);
let application = Application.create(attributes);
setApplication(application);
start();
{
"version": "0.17.2",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true,
"_APPLICATION_TEMPLATE_WRAPPER": false,
"_JQUERY_INTEGRATION": false
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment