reactjs - 我如何在反应应用程序中添加 sitemap.xml 并公开?
问题描述
我在文件夹中的文件中有一个 sitemap.xml,/public
我想将其公开,以便 Google 可以从 www.my_domain.com/sitemap.xml 读取它。我怎么做?
编辑 我已经接管了这个项目,我不知道这种设置。这就是我现在所拥有的。
// Set up the router, wrapping all Routes in the App component
import App from 'containers/App';
import createRoutes, { createIndexRoute } from './routes';
const rootRoute = {
path: '/(en)(pl)(de)(bg)(cz)(ee)(gr)(hr)(hu)(it)(lt)(lv)(ro)(si)(sk)',
component: App,
childRoutes: createRoutes(store),
indexRoute: createIndexRoute(store),
};
const render = (translatedMessages) => {
ReactDOM.render(
<Provider store={store}>
<LanguageProvider messages={translatedMessages}>
<Router
history={history}
routes={rootRoute}
render={applyRouterMiddleware(
useScroll(
(prevRouterProps, { location }) =>
prevRouterProps && location.pathname !== prevRouterProps.location.pathname
)
)}
/>
</LanguageProvider>
</Provider>,
document.getElementById('app')
);
};
每条路线看起来像这样
###routes.js
export default function createRoutes(store) {
// Create reusable async injectors using getAsyncInjectors factory
const { injectReducer, injectSagas } = getAsyncInjectors(store);
return [
{
path: '/home',
name: 'home',
getComponent(nextState, cb) {
const importModules = Promise.all([
System.import('containers/HomePage/reducer'),
System.import('containers/HomePage/sagas'),
System.import('containers/HomePage'),
]);
const renderRoute = loadModule(cb);
importModules.then(([reducer, sagas, component]) => {
injectReducer('home', reducer.default);
injectSagas(sagas.default);
renderRoute(component);
});
importModules.catch(errorLoading);
},
}
]
}
我只想要一条路线/sitemap.xml
解决方案
我通过将 xml 添加到我的服务器重写规则来解决。
它是</^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|ttf)$).)*$/>
更新为</^((?!\.(css|gif|ico|jpg|js|png|txt|svg|woff|xml|ttf)$).)*$/>
当我访问 /sitemap.xml 时,我现在可以看到站点地图在它显示页面未找到路线之前的位置。
推荐阅读
- invoice - Xero Api 如何标记发票已付款
- symfony - 在 EasyAdmin 3.x 中使用 autocomplete() 时如何设置 AssociationField 选项标签
- javascript - 用于集成的 Maximo 自动化脚本 - JSON
- apache-spark - 使用 Pyspark 中条件的 Dataframe 上的 Groupby 函数
- javascript - 方法中的 const 未定义
- java - 未将元素添加到我的数组列表中
- c# - 如何知道接下来按下哪个按钮c#
- html - 使用 z-index 时的流体测量
- machine-learning - 使用交叉验证的模型选择
- java - 在java中打印时防止控制台接受输入?