Redirect user on invalid topic slug
This commit is contained in:
parent
775bff5c1b
commit
ad560bb4ef
|
|
@ -9,6 +9,7 @@ import {typeDefs} from '@/graphql/typedefs';
|
||||||
import {resolvers} from '@/graphql/resolvers';
|
import {resolvers} from '@/graphql/resolvers';
|
||||||
import cache from './cache';
|
import cache from './cache';
|
||||||
|
|
||||||
|
import {router} from '@/router';
|
||||||
|
|
||||||
export default function (uri, networkErrorCallback) {
|
export default function (uri, networkErrorCallback) {
|
||||||
const httpLink = createHttpLink({
|
const httpLink = createHttpLink({
|
||||||
|
|
@ -64,19 +65,37 @@ export default function (uri, networkErrorCallback) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const notFoundLink = new ApolloLink((operation, forward) => {
|
||||||
|
return forward(operation).map(response => {
|
||||||
|
const {data} = response;
|
||||||
|
if (data) {
|
||||||
|
if (data.topic && data.topic.__typename === 'NotFound') {
|
||||||
|
// redirect to general 404 page.
|
||||||
|
// todo: specific topic not found page, with navigation?
|
||||||
|
router.push({
|
||||||
|
name: 'not-found'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
let composedLink;
|
let composedLink;
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
composedLink = ApolloLink.from([
|
composedLink = ApolloLink.from([
|
||||||
createOmitTypenameLink,
|
createOmitTypenameLink,
|
||||||
errorLink,
|
errorLink,
|
||||||
httpLink
|
notFoundLink,
|
||||||
|
httpLink,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
composedLink = ApolloLink.from([
|
composedLink = ApolloLink.from([
|
||||||
consoleLink,
|
consoleLink,
|
||||||
createOmitTypenameLink,
|
createOmitTypenameLink,
|
||||||
errorLink,
|
errorLink,
|
||||||
httpLink
|
notFoundLink,
|
||||||
|
httpLink,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fragment NotFoundParts on NotFound {
|
||||||
|
reason
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#import "../fragments/topicParts.gql"
|
#import "../fragments/topicParts.gql"
|
||||||
|
#import "../fragments/notFoundParts.gql"
|
||||||
query Topic($slug: String!){
|
query Topic($slug: String!){
|
||||||
topic(slug: $slug) {
|
topic(slug: $slug) {
|
||||||
...TopicParts
|
...TopicParts
|
||||||
|
...NotFoundParts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
BookTopicNavigation,
|
BookTopicNavigation,
|
||||||
ModuleTeaser,
|
ModuleTeaser,
|
||||||
PlayIcon,
|
PlayIcon,
|
||||||
BulbIcon
|
BulbIcon,
|
||||||
},
|
},
|
||||||
|
|
||||||
apollo: {
|
apollo: {
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
return {
|
return {
|
||||||
query: TOPIC_QUERY,
|
query: TOPIC_QUERY,
|
||||||
variables: {
|
variables: {
|
||||||
slug: this.$route.params.topicSlug
|
slug: this.$route.params.topicSlug,
|
||||||
},
|
},
|
||||||
update(data) {
|
update(data) {
|
||||||
return this.$getRidOfEdges(data).topic || {};
|
return this.$getRidOfEdges(data).topic || {};
|
||||||
|
|
@ -81,26 +81,26 @@
|
||||||
this.saveMe = false;
|
this.saveMe = false;
|
||||||
this.updateLastVisitedTopic(this.topic.id);
|
this.updateLastVisitedTopic(this.topic.id);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
topic: {
|
topic: {
|
||||||
modules: {
|
modules: {
|
||||||
edges: []
|
edges: [],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
saveMe: false
|
saveMe: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
modules() {
|
modules() {
|
||||||
return this.topic.modules;
|
return this.topic.modules;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
@ -116,12 +116,15 @@
|
||||||
this.$store.dispatch('showFullscreenVideo', this.topic.vimeoId);
|
this.$store.dispatch('showFullscreenVideo', this.topic.vimeoId);
|
||||||
},
|
},
|
||||||
updateLastVisitedTopic(topicId) {
|
updateLastVisitedTopic(topicId) {
|
||||||
|
if (!topicId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
mutation: UPDATE_LAST_TOPIC_MUTATION,
|
mutation: UPDATE_LAST_TOPIC_MUTATION,
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
id: topicId
|
id: topicId,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
update(store, {data: {updateLastTopic: {topic}}}) {
|
update(store, {data: {updateLastTopic: {topic}}}) {
|
||||||
if (topic) {
|
if (topic) {
|
||||||
|
|
@ -131,15 +134,15 @@
|
||||||
const data = {
|
const data = {
|
||||||
me: {
|
me: {
|
||||||
...me,
|
...me,
|
||||||
lastTopic: topic
|
lastTopic: topic,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
store.writeQuery({query, data});
|
store.writeQuery({query, data});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,18 @@ const submission = () => import('@/pages/studentSubmission');
|
||||||
|
|
||||||
const postLoginRedirectUrlKey = 'postLoginRedirectionUrl';
|
const postLoginRedirectUrlKey = 'postLoginRedirectionUrl';
|
||||||
|
|
||||||
|
const notFoundRoute = {
|
||||||
|
component: p404,
|
||||||
|
meta: {
|
||||||
|
layout: 'blank',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
component: start
|
component: start,
|
||||||
},
|
},
|
||||||
...moduleRoutes,
|
...moduleRoutes,
|
||||||
...authRoutes,
|
...authRoutes,
|
||||||
|
|
@ -85,15 +92,17 @@ const routes = [
|
||||||
default:
|
default:
|
||||||
return '/unknown-auth-error';
|
return '/unknown-auth-error';
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{path: '/styleguide', component: styleGuidePage},
|
{path: '/styleguide', component: styleGuidePage},
|
||||||
|
{
|
||||||
|
path: '/not-found',
|
||||||
|
name: 'not-found',
|
||||||
|
...notFoundRoute
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
component: p404,
|
...notFoundRoute
|
||||||
meta: {
|
|
||||||
layout: 'blank',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue