簡體   English   中英

從我的頁面中刪除'.ghtml'在react-router-dom

[英]remove '.ghtml' from my pages in react-router-dom

我在此配置中使用react-router-dom(4.1.1):

import React from 'react';
import { BrowserRouter as Router, Route, Switch, Redirect} from 'react-router-dom';

import App from './app/App.js';
const Wildcard = () => <Redirect to="/" />;
const Routes = () => (
  <Router> 
    <div>
      <Switch>
        <Route exact path="/" component={App} />
        <Route exact path="/:section/:news/:title" component={App} />
        <Route exact path="/*" render={Wildcard} />
      </Switch>
    </div>
  </Router>
); 

export default Routes;

我希望此網址“ localhost:3000 / section / news / title.ghtml”在第二個條件下匹配,但是我得到了:

Cannot GET /section/news/title.ghtml

當我刪除.ghtml時,它工作正常。

這是反應路由器可以理解.ghtml的一種方式嗎?

解決了Vanila Javascript的問題:

  const url = location.pathname.replace('.ghtml','');
  history.replaceState(null,null,url);

簡而言之,希望對這個問題有幫助的人

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM