Skip to content

Commit

Permalink
Remove localized "server-error" route. (#734)
Browse files Browse the repository at this point in the history
This fixes an issue where the `Reference` component is mistakenly using
a <router-link> to render a /downloads/ link, which doesn't work since
those URLs are used for static file downloads, not Vue routes.

Resolves: rdar://115733855
  • Loading branch information
mportiz08 authored Sep 20, 2023
1 parent ef5e5d0 commit b6cf582
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/constants/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// The name of the "not found" route.
export const notFoundRouteName = 'not-found';
// The name of the "server error" route.
export const serverErrorRouteName = 'server-error';
// The dynamic imports with special `webpackChunkName` comments are used to
// take advantage of webpack's code-splitting functionality to break apart
// optimized JavaScript bundles for each route on demand.
Expand Down
8 changes: 6 additions & 2 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import { documentationTopicName, notFoundRouteName } from 'docc-render/constants/router';
import {
documentationTopicName,
notFoundRouteName,
serverErrorRouteName,
} from 'docc-render/constants/router';
import ServerError from 'theme/views/ServerError.vue';
import NotFound from 'theme/views/NotFound.vue';

Expand Down Expand Up @@ -41,7 +45,7 @@ export default [
},
{
path: '*', // purposefully unreachable without a forced navigation
name: 'server-error',
name: serverErrorRouteName,
component: ServerError,
},
];
13 changes: 11 additions & 2 deletions src/setup-utils/SwiftDocCRenderRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/

import Router from 'vue-router';
import {
notFoundRouteName,
serverErrorRouteName,
} from 'docc-render/constants/router';
import {
saveScrollOnReload,
restoreScrollOnReload,
Expand All @@ -17,9 +21,14 @@ import {
import routes from 'docc-render/routes';
import { baseUrl } from 'docc-render/utils/theme-settings';
import { addPrefixedRoutes } from 'docc-render/utils/route-utils';
import { notFoundRouteName } from 'docc-render/constants/router';

const defaultRoutes = [...routes, ...addPrefixedRoutes(routes, [notFoundRouteName])];
const defaultRoutes = [
...routes,
...addPrefixedRoutes(routes, [
notFoundRouteName,
serverErrorRouteName,
]),
];

export default function createRouterInstance(routerConfig = {}) {
const router = new Router({
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/components/ContentNode/Reference.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,17 @@ describe('Reference', () => {
// add query params to url
expect(wrapper.find(ReferenceExternal).props('url')).toBe('http://website.com');
});

it('renders a `ReferenceExternal` for /downloads/ URLs', () => {
const wrapper = shallowMount(Reference, {
localVue,
router,
propsData: { url: '/downloads/foo.zip' },
slots: { default: 'Foo' },
});
const ref = wrapper.find(ReferenceExternal);
expect(ref.exists()).toBe(true);
expect(ref.props('url')).toBe('/downloads/foo.zip');
expect(ref.text()).toBe('Foo');
});
});

0 comments on commit b6cf582

Please sign in to comment.