Skip to content

Commit

Permalink
Implement 404 page as in the API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MinThaMie committed Jul 23, 2024
1 parent ecdb88f commit 34cf22d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Router.map(function () {
});

this.route('id', { path: 'id/:id' });
this.route('not-found');
this.route('new-test');
});
7 changes: 7 additions & 0 deletions app/routes/ember.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Route from '@ember/routing/route';
import processResults from '../utils/process-results';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class EmberRoute extends Route {
@service store;
@service router;

controllerName = 'show';
templateName = 'show';
Expand All @@ -19,4 +21,9 @@ export default class EmberRoute extends Route {
sorted: processResults(query),
};
}

@action
error() {
this.router.transitionTo('not-found');
}
}
8 changes: 7 additions & 1 deletion app/routes/id.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

import { action } from '@ember/object';
export default class IdPRoute extends Route {
@service store;
@service router;

model(params) {
return this.store.findRecord('content', params.id);
}

@action
error() {
this.router.transitionTo('not-found');
}
}
3 changes: 3 additions & 0 deletions app/routes/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Route from '@ember/routing/route';

export default class NotFoundRoute extends Route {}
7 changes: 7 additions & 0 deletions app/routes/show.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Route from '@ember/routing/route';
import processResults from '../utils/process-results';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';

export default class ShowRoute extends Route {
@service store;
@service router;

async model(params) {
let query = await this.store.query('content', {
Expand All @@ -16,4 +18,9 @@ export default class ShowRoute extends Route {
sorted: processResults(query),
};
}

@action
error() {
this.router.transitionTo('not-found');
}
}
30 changes: 30 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,36 @@ table {
padding: 2rem;
}

// 404 styling
.whoops {
display: flex;
justify-content: center;
align-items: center;
padding: var(--spacing-6)
}

.whoops img {
width: 240px;
margin: var(--spacing-2);
}

@media (max-width: 450px) {
.whoops {
flex-direction: column;
padding: var(--spacing-3);
}

.whoops img {
width: 80%;
margin: var(--spacing-4);
}

.whoops__message {
margin: var(--spacing-2);
text-align: center;
}
}

// override ember-styleguide. Needed to contain code blocks.
.main {
grid-area: main;
Expand Down
9 changes: 9 additions & 0 deletions app/templates/not-found.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{page-title "Page Not Found"}}

<article class="whoops">
<img src="/images/stinky-fish.png" alt="tomster stinky fish"/>
<div class="whoops__message">
<h2>Ack! 404 friend, you're in the wrong place</h2>
<LinkTo @route='index'>Click here to go home</LinkTo>
</div>
</article>
Binary file added public/images/stinky-fish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 34cf22d

Please sign in to comment.