所以这里列出了我所做的事情。希望这可以帮助。
我们需要删除每个网址的路径中的#号,因为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',我该怎么做? –
此方法对我无效 –