Я использую паспорт-js с реактивным стартером и универсальным маршрутизатором, и есть некоторые/логины входа, которые обрабатываются на стороне сервера. Есть ли способ принудительного извлечения на стороне сервера URL-адреса маршрута, а не клиентского?Как заставить серверную службу обслуживать маршрут
Например, если я иду или выхожу прямо из URL-адреса, это вызывает правильное выключение на стороне сервера. Однако, если я нажимаю на ссылку/logout в браузере с клиентской стороны, я получаю сообщение об ошибке страницы, потому что он выполняет маршрутизацию на стороне клиента и/выход из системы не определяется в маршрутах. Можно ли определить объект маршрута, который должен обслуживаться непосредственно с сервера?
маршруты/index.js
export default {
path: '/',
// Keep in mind, routes are evaluated in order
children: [
require('./home').default,
require('./contact').default,
require('./register').default,
require('./termsOfUse').default,
require('./privacyPolicy').default,
require('./invites').default,
require('./collection').default,
require('./profile').default,
require('./content').default,
require('./notFound').default,
// Wildcard routes, e.g. { path: '*', ... } (must go last)
],
async action({ next }) {
// Execute each child route until one of them return the result
const route = await next();
// Provide default values for title, description etc.
route.title = `${route.title}`;
route.description = route.description || '';
return route;
},
};
client.js
sync function onLocationChange(location) {
// my workaround is to put a special case for login and logout
// but it feels a bit of a hack since this logic should be set in the routing
// config if possible
if (location.pathname === '/login' || location.pathname === '/logout') {
// break - let passport.js handle it via server-side
window.location.reload();
return;
}
...
currentLocation = location;
try {
// Traverses the list of routes in the order they are defined until
// it finds the first route that matches provided URL path string
// and whose action method returns anything other than `undefined`.
const route = await UniversalRouter.resolve(routes, {
...context,
path: location.pathname,
query: queryString.parse(location.search),
});
// Prevent multiple page renders during the routing process
if (currentLocation.key !== location.key) {
return;
}
if (route.redirect) {
history.replace(route.redirect);
return;
}
const component = (
<App context={context}>
<ApolloProvider client={context.client} store={context.store}>
{route.component}
</ApolloProvider>
</App>
);
appInstance = ReactDOM.render(
component,
container,
() => onRenderComplete(route, location),
);
} catch (error) {
console.error(error); // eslint-disable-line no-console
// Current url has been changed during navigation process, do nothing
if (currentLocation.key !== location.key) {
return;
}
// Display the error in full-screen for development mode
if (process.env.NODE_ENV !== 'production') {
appInstance = null;
document.title = `Error: ${error.message}`;
ReactDOM.render(<ErrorReporter error={error} />, container);
return;
}
// Avoid broken navigation in production mode by a full page reload on error
window.location.reload();
}
}
вы имели в виду вы хотите, чтобы иметь возможность нажать на ссылку/выход из системы в клиенте, затем перенаправить на некоторую страницу и получить ответ на серверную сторону? –
yes Я хочу, чтобы он работал как обычная ссылка http, а не изоморфная маршрутизация на стороне клиента - я хочу, чтобы она выполняла явную загрузку страницы. В настоящее время мое исправление заключается в том, чтобы перейти в client.js и вырезать случай, когда маршрут/логин, но не уверен, что это правильный путь – MonkeyBonkey