FIX: Compatibility between Client and Server routing.
mend
This commit is contained in:
parent
c1f174f554
commit
a370d7c7fd
|
@ -29,6 +29,8 @@ export function loadTopicView(topic, args) {
|
|||
});
|
||||
}
|
||||
|
||||
export const ID_CONSTRAINT = /^\d+$/;
|
||||
|
||||
const Topic = RestModel.extend({
|
||||
message: null,
|
||||
errorLoading: false,
|
||||
|
|
|
@ -9,7 +9,8 @@ export default function() {
|
|||
this.route('fromParams', { path: '/' });
|
||||
this.route('fromParamsNear', { path: '/:nearPost' });
|
||||
});
|
||||
this.route('topicBySlug', { path: '/t/:slug', resetNamespace: true });
|
||||
|
||||
this.route('topicBySlugOrId', { path: '/t/:slugOrId', resetNamespace: true });
|
||||
this.route('topicUnsubscribe', { path: '/t/:slug/:id/unsubscribe' });
|
||||
|
||||
this.route('discovery', { path: '/', resetNamespace: true }, function() {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { default as Topic, ID_CONSTRAINT } from 'discourse/models/topic';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model(params) {
|
||||
if (params.slugOrId.match(ID_CONSTRAINT)) {
|
||||
return { url: `/t/topic/${params.slugOrId}` };
|
||||
} else {
|
||||
return Topic.idForSlug(params.slugOrId);
|
||||
}
|
||||
},
|
||||
|
||||
afterModel(result) {
|
||||
DiscourseURL.routeTo(result.url, { replaceURL: true });
|
||||
}
|
||||
});
|
|
@ -1,12 +0,0 @@
|
|||
import Topic from 'discourse/models/topic';
|
||||
import DiscourseURL from 'discourse/lib/url';
|
||||
|
||||
export default Discourse.Route.extend({
|
||||
model: function(params) {
|
||||
return Topic.idForSlug(params.slug);
|
||||
},
|
||||
|
||||
afterModel: function(result) {
|
||||
DiscourseURL.routeTo(result.url, { replaceURL: true });
|
||||
}
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import DiscourseURL from 'discourse/lib/url';
|
||||
import { ID_CONSTRAINT } from 'discourse/models/topic';
|
||||
|
||||
let isTransitioning = false,
|
||||
scheduledReplace = null,
|
||||
|
@ -157,6 +158,10 @@ const TopicRoute = Discourse.Route.extend({
|
|||
},
|
||||
|
||||
model(params, transition) {
|
||||
if (params.slug.match(ID_CONSTRAINT)) {
|
||||
return DiscourseURL.routeTo(`/t/topic/${params.slug}/${params.id}`, { replaceURL: true });
|
||||
};
|
||||
|
||||
const queryParams = transition.queryParams;
|
||||
|
||||
let topic = this.modelFor('topic');
|
||||
|
|
|
@ -142,6 +142,26 @@ QUnit.test("Reply as new message", assert => {
|
|||
});
|
||||
});
|
||||
|
||||
QUnit.test("Visit topic routes", assert => {
|
||||
visit("/t/12");
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(
|
||||
find('.fancy-title').text().trim(), 'PM for testing',
|
||||
'it routes to the right topic'
|
||||
);
|
||||
});
|
||||
|
||||
visit("/t/280/20");
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(
|
||||
find('.fancy-title').text().trim(), 'Internationalization / localization',
|
||||
'it routes to the right topic'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test("Updating the topic title with emojis", assert => {
|
||||
visit("/t/internationalization-localization/280");
|
||||
click('#topic-title .d-icon-pencil');
|
||||
|
|
|
@ -131,6 +131,7 @@ export default function() {
|
|||
this.put('/u/eviltrout.json', () => response({ user: {} }));
|
||||
|
||||
this.get("/t/280.json", () => response(fixturesByUrl['/t/280/1.json']));
|
||||
this.get("/t/280/20.json", () => response(fixturesByUrl['/t/280/1.json']));
|
||||
this.get("/t/28830.json", () => response(fixturesByUrl['/t/28830/1.json']));
|
||||
this.get("/t/9.json", () => response(fixturesByUrl['/t/9/1.json']));
|
||||
this.get("/t/12.json", () => response(fixturesByUrl['/t/12/1.json']));
|
||||
|
|
Loading…
Reference in New Issue