0
저는 react-starter-kit 및 universal router와 함께 passport-js를 사용하고 있으며 서버 측에서 처리되는 일부/로그인 경로가 있습니다. 클라이언트 쪽 경로 URL이 아닌 경로 URL에서 강제로 서버 쪽을 가져 오는 방법이 있습니까?서버 측 경로를 강제로 수행하는 방법
예를 들어 url에서/logout으로 직접 이동하면 올바른 서버 측 로그 아웃이 트리거됩니다. 그러나 클라이언트 쪽에서 브라우저의/logout 링크를 클릭하면 클라이언트 쪽 라우팅을 수행하고/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();
}
}
는 당신이 클릭 할 수 있도록하려면하셨습니까 발견/로그 아웃 링크 클라이언트에서 다음 일부 페이지로 리디렉션 및 서버 쪽 응답을 가져옵니다? –
예 동형 클라이언트 측 라우팅이 아닌 일반 http 링크로 작동하도록하고 싶습니다. 명시 적 페이지로드를 원합니다. 현재 나의 수정점은 client.js에 들어가서 경로가/login 일 경우에 대한 사례를 작성하지만 올바른 방법인지는 확실하지 않습니다. – MonkeyBonkey