我试图从Angular 4中的URL中删除#符号

时间:2018-01-31 10:15:35

标签: javascript angular angular4-router

我正在使用PathLocationStrategy并添加以下代码

imports: [
    ...
    RouterModule.forRoot(routes, { useHash: true })  // remove second argument
]

但已从网址中删除,但刷新页面时会发生以下错误

  

页面未找到

2 个答案:

答案 0 :(得分:0)

删除哈希后,开始使用import wx import wx.html as wxhtml from docutils.core import publish_string class MainFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = MainPanel(self) sizer = wx.BoxSizer() sizer.Add(self.panel) self.SetSizerAndFit(sizer) self.Show() input_string = ("Heading\n" "=======\n" "\n" "1. With 24 widgets pull a **long** one;\n" "2. with fewer, push a **wide** one.\n") self.display_rst(input_string) def display_rst(self, rst): html = publish_string(rst, writer_name='html') self.panel.html.SetPage(html) class MainPanel(wx.Panel): def __init__(self, parent, *args, **kwargs): wx.Panel.__init__(self, parent, *args, **kwargs) display_style = wx.VSCROLL|wx.HSCROLL|wx.TE_READONLY|wx.BORDER_SIMPLE self.html = wxhtml.HtmlWindow(self, -1, size=(300, 200), style=display_style) sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.html) self.SetSizer(sizer) if __name__ == "__main__": SCREEN_APP = wx.App() MAIN_FRAME = MainFrame(None, title="Display HTML") SCREEN_APP.MainLoop() 路由机制。要使用此功能,您需要配置 Web服务器以支持您托管网站的HTML5路由机制。每个Web服务器的配置不同。

答案 1 :(得分:0)

您可以将网络服务器默认设置为index.html

<强> nginx的

server {
    listen       80;
    server_name  localhost;


    location / {
      root   /usr/share/nginx/html;
      index  index.html index.htm;
      try_files $uri $uri/ /index.html;
    }
}

<强> apache2的

使用此内容创建.htaccess文件

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>