所以這裏列出了我所做的事情。希望這可以幫助。
我們需要刪除每個網址的路徑中的#號,因爲Google Analytics拒絕其中包含#個網址。在APP模塊,{locationStrategy: '路徑'}添加到你的應用程序模塊,如下所示:
IonicModule.forRoot(MyApp, {
locationStrategy: 'path'
})
2。現在#從URL中刪除。但是,當你刷新或直接訪問網址,這將無法正常工作,因爲這是任何SPA的預期行爲。刷新頁面時,服務器試圖在所提及的位置查找頁面。正如@Parth Ghiya上面所說的對於例如:如果你打localhost/abc,那麼服務器會試圖找到abc/index.html實際上不存在的。所以爲了解決這個問題,你在我的服務器上寫了配置,請求index.html。我正在使用節點快遞服務器來部署應用程序。使用下面的代碼來路由每個請求的index.html -
var express = require('express');
var path = require('path')
var app = express();
app.use(express.static(path.resolve(__dirname, "www")));
app.use('/*', function(req, res){
res.sendFile(__dirname+ '/www' + '/index.html');
});
app.set('port', process.env.PORT || 3000);
app.listen(app.get('port'), function() {
console.log("listening to Port", app.get("port"));
});
我試圖在這兩個,但沒有工作,給運行時錯誤 - \t @NgModule({ \t \t進口:[IonicModule.forRoot( MyApp的,{locationStrategy: '路徑'},{ \t \t鏈接:[ \t \t \t {組分:RegistrationComponent,名稱: '註冊',段: '登記'} \t \t] \t \t})], \t \t提供商:[...] \t}) \t @NgModule({ \t \t進口:[IonicModule。forRoot(MyApp的,{},{ \t \t鏈接:[{組分:RegistrationComponent,名稱: '註冊',段: '登記'},] \t \t})], \t \t提供商:[{提供:LocationStrategy ,useClass:PathLocationStrategy},...] \t}) –
嗨,我需要傳遞一個參數,例如'http:// localhost:8100/feedback/767',我該怎麼做? –
此方法對我無效 –